Martijn van Amsterdam
Martijn van Amsterdam

Reputation: 326

Drop all rows from a dataframe based on value

I have been looking this site and google for an answer to my question, but they all apply to columns.

In my data set there are a couple of cells which only contain a space, instead of NaN. So I would like to drop all the rows there this is the case. I know I can use the code below to do so per column. But how do I apply this to the entire dataframe?

df= df[df.column != ' ']

Upvotes: 0

Views: 44

Answers (1)

jezrael
jezrael

Reputation: 862396

If need remove all rows with space at least in one column add DataFrame.all for test if all values per rows are Trues:

df= df[(df != ' ').all(axis=1)]

Upvotes: 3

Related Questions