How to find which columns contain any NaN value in Pandas dataframe

前端 未结 8 1612
醉酒成梦
醉酒成梦 2020-11-28 02:17

Given a pandas dataframe containing possible NaN values scattered here and there:

Question: How do I determine which columns contain NaN values? In

相关标签:
8条回答
  • 2020-11-28 02:51

    Both of these should work:

    df.isnull().sum()
    df.isna().sum()
    

    DataFrame methods isna() or isnull() are completely identical.

    Note: Empty strings '' is considered as False (not considered NA)

    0 讨论(0)
  • 2020-11-28 02:56

    df.isna() return True values for NaN, False for the rest. So, doing:

    df.isna().any()

    will return True for any column having a NaN, False for the rest

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