Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

python - 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 != ' ']

question from:https://stackoverflow.com/questions/65917369/drop-all-rows-from-a-dataframe-based-on-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...