Count number of non-NaN entries in every column of Dataframe

前端 未结 2 1699
长情又很酷
长情又很酷 2020-12-13 23:48

I have a really big DataFrame and I was wondering if there was short (one or two liner) way to get the a count of non-NaN entries in a DataFrame. I don\'t want to do this on

相关标签:
2条回答
  • 2020-12-14 00:02

    If you want to sum the total count values which are not NAN, one can do;

    np.sum(df.count())
    
    0 讨论(0)
  • 2020-12-14 00:12

    The count() method returns the number of non-NaN values in each column:

    >>> df1.count()
    a    3
    b    2
    d    1
    dtype: int64
    

    Similarly, count(axis=1) returns the number of non-NaN values in each row.

    0 讨论(0)
提交回复
热议问题