Reputation: 9527
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!
Upvotes: 10
Views: 16192
Reputation: 73
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)
Upvotes: 6
Reputation: 2708
Surprisingly I got following output after execution the code you given:
calculate length of series object and subtraction will give you the count for null values. As follows:**
len(ser)-(ser[ser.isnull()==False]).count()
Upvotes: 1
Reputation: 732
To get around this, you can also do
series.apply(lambda x: str(x) == "nat")
Then you can still use np.datetime if you want
Upvotes: 0