【发布时间】:2020-11-08 10:48:14
【问题描述】:
我有一个多索引数据框。如果任何单元格为 NaN,我想要做的是删除列,然后获取 0 级索引的名称。
data=
A B C
d e f g h i
0 1 2 3 4 NaN NaN
1 1 2 3 4 NaN NaN
2 1 2 3 4 NaN NaN
3 1 2 3 4 NaN NaN
我使用了data.dropna(axis= 1, inplace= True),得到了如下结果。
A B
d e f g
0 1 2 3 4
1 1 2 3 4
2 1 2 3 4
3 1 2 3 4
现在我使用了 print(list(data.columns.levels[0])) 但显示以下输出。
['A', 'B', 'C']
我如何只得到 ['A', 'B']?
提前致谢。
【问题讨论】: