Reputation: 15
I need to select a row where age is NaN in Pandas
df[df['age']==np.nan]
This does not return anything. But my dataset has a row where age is NaN
Upvotes: 0
Views: 56
Reputation: 391
df = pd.DataFrame({'age': [15,np.nan, 30, 40]})
print(df)
age
0 15.0
1 NaN
2 30.0
3 40.0
df['age'].isna()
will give True for the rows that are nan:
0 False
1 True
2 False
3 False
Then you can find the rows and their values (which is nan) by using df[df['age'].isna()]
:
age
1 NaN
Upvotes: 1