Reputation: 603
I know the df.count() and df.groupby.count(), but I simply want the number of non-NAN elements for a specific column (say called 'cars') of my dataframe.
I know df.size[0], but this command does not respect the fact that the number of non-NAN elements might differ in different columns.
Upvotes: 1
Views: 2809
Reputation: 25249
There is also Series count
. It also ignores NaN
. From the docs
s = pd.Series([0.0, 1.0, np.nan])
s.count()
Out[307]: 2
So, for column cars
df['cars'].count()
will return number of Non-NaN values of column cars
Upvotes: 4