I have a massive DataFrame, and I was wondering if there was a short (one or two liner) way to get a count of non-NaN entries in a DataFrame. I don't want to do this one column at a time as I have close to 1000 columns.
df1 = pd.DataFrame([(1,2,None),(None,4,None),(5,None,7),(5,None,None)],
columns=['a','b','d'], index = ['A', 'B','C','D'])
a b d
A 1 2 NaN
B NaN 4 NaN
C 5 NaN 7
D 5 NaN NaN
Output:
a: 3
b: 2
d: 1
df1.notnull()
is not necessary sincecount
ignores null values anyway. – Welldefinedseries.value_counts(..., dropna=False)
, there is no option ondf.count()
to directly get NA counts. – Ogham