Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python pandas .isnull() does not work on NaT in object dtype

I have this series:

ser=pd.Series([11,22,33,np.nan,np.datetime64('nat')],name='my_series')

The series looks like this:

0     11
1     22
2     33
3    NaN
4    NaN
Name: my_series, dtype: object

But I get only one True for NULL values:

ser.isnull()

0    False
1    False
2    False
3     True
4    False
Name: my_series, dtype: bool

Is it a bug or how can I count correctly the NULL values in a pandas series? This does not help:

ser=ser.replace('NaN',np.nan)

Thanks!

like image 327
ragesz Avatar asked Sep 30 '15 10:09

ragesz


1 Answers

I ran into a similar issue this morning but in an str series! This worked for me and with your sample data as well:

pd.isna(ser)

like image 79
nck Avatar answered Oct 26 '22 22:10

nck