Aly
Aly

Reputation: 367

How to remove observations with missing values for specific columns from pandas DataFrame?

I have pandas DataFrame containing columns with missing values. I want remove observations, rows with them but only for specific columns. For example:

A    B    C    D    E 
2    1    NaN   7   9 
1    3    6    NaN  10 
NaN  3    11    0   8

And let's say I want to remove observations with missing value for column D. So I want result like this:

A    B    C    D    E 
2    1    NaN   7   9 
NaN  3    11    0   8

Thank you for all suggestions.

Upvotes: 1

Views: 370

Answers (1)

wwnde
wwnde

Reputation: 26676

Lets try mask pd.Series.notna()

 df[df.D.notna()]



 A  B     C    D  E
0  2.0  1   NaN  7.0  9
2  NaN  3  11.0  0.0  8

Upvotes: 1

Related Questions