How to Remove Rows With Any Zero Value

Drop rows with all zeros in pandas data frame

It turns out this can be nicely expressed in a vectorized fashion:

> df = pd.DataFrame({'a':[0,0,1,1], 'b':[0,1,0,1]})
> df = df[(df.T != 0).any()]
> df
a b
1 0 1
2 1 0
3 1 1

How to remove rows from a DataFrame where some columns only have zero values

try this,

df[~df[list('cdef')].eq(0).all(axis = 1)]


    a   b   c   d   e   f
0 1 2 3 4 5 6
1 11 22 33 44 55 66

Drop row in pandas dataframe if any value in the row equals zero

i think the easiest way is looking at rows where all values are not equal to 0:

df[(df != 0).all(1)]

How to remove rows with any zero value

There are a few different ways of doing this. I prefer using apply, since it's easily extendable:

##Generate some data
dd = data.frame(a = 1:4, b= 1:0, c=0:3)

##Go through each row and determine if a value is zero
row_sub = apply(dd, 1, function(row) all(row !=0 ))
##Subset as usual
dd[row_sub,]

remove R Dataframe rows based on zero values in one column

Just subset the data frame based on the value in the No_of_Mails column:

df[df$No_of_Mails != 0, ]

Demo



Related Topics



Leave a reply



Submit