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

ragesz picture ragesz · Sep 30, 2015 · Viewed 10.3k times · Source

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!

Answer

nck picture nck · Apr 9, 2019

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)