pandas dataframe drop columns by number of nan

后端 未结 5 835
忘了有多久
忘了有多久 2021-01-04 02:08

I have a dataframe with some columns containing nan. I\'d like to drop those columns with certain number of nan. For example, in the following code, I\'d like to drop any co

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-04 02:20

    You can use a conditional list comprehension:

    >>> dff[[c for c in dff if dff[c].isnull().sum() < 2]]
              A         B
    0 -0.819004  0.919190
    1  0.922164  0.088111
    2  0.188150  0.847099
    3       NaN -0.053563
    4  1.327250 -0.376076
    5  3.724980  0.292757
    6 -0.319342       NaN
    7 -1.051529  0.389843
    8 -0.805542 -0.018347
    9 -0.816261 -1.627026
    

提交回复
热议问题