Python 3.x 使用Pandas查找具有最大缺失值的列

Python 3.x 使用Pandas查找具有最大缺失值的列,python-3.x,pandas,missing-data,Python 3.x,Pandas,Missing Data,我是Python新手。我想找出我的数据框中哪列有最大缺失值。假设我们有5行1000列。 比如说 C1 C2 ... C1000 10 21 ... NaN NaN 45 ... 29 15 21 ... NaN 21 NaN ... 27 61 NaN ... NaN C1000具有最大缺失值。因此,我的代码应该返回列名“C1000”您可以使用df.count().idxmin()d

我是Python新手。我想找出我的数据框中哪列有最大缺失值。假设我们有5行1000列。
比如说

C1    C2    ...   C1000  
10    21    ...   NaN  
NaN   45    ...   29  
15    21    ...   NaN  
21    NaN   ...   27  
61    NaN   ...   NaN 

C1000具有最大缺失值。因此,我的代码应该返回列名“C1000”

您可以使用
df.count().idxmin()
df.count()。而且,
idxmin
将为您提供包含大多数非NA/null值的列

In [12]: df
Out[12]:
     C1    C2  C1000
0  10.0  21.0    NaN
1   NaN  45.0   29.0
2  15.0  21.0    NaN
3  21.0   NaN   27.0
4  61.0   NaN    NaN

In [13]: df.count()
Out[13]:
C1       4
C2       3
C1000    2
dtype: int64

In [14]: df.count().idxmin()
Out[14]: 'C1000'