在PANDAS中删除标题的第二行 [英] Delete second row of header in PANDAS
本文介绍了在PANDAS中删除标题的第二行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在PANDAS中有一个数据帧,其中有两行标题,如何删除第二行?例如,我有以下内容:
I have a dataframe in PANDAS which has two lines of headers.How could I remove the second line? For example, I have the following:
AA BB CC DD
A B C D
Index
1 1 2 3 4
2 5 6 7 8
3 9 1 2 3
我想得到这样的东西:
AA BB CC DD
Index
1 1 2 3 4
2 5 6 7 8
3 9 1 2 3
非常感谢您.
推荐答案
You can use droplevel
with -1
: last level:
df.columns = df.columns.droplevel(-1)
print df
AA BB CC DD
Index
1 1 2 3 4
2 5 6 7 8
3 9 1 2 3
或指定第二级:1
:
df.columns = df.columns.droplevel(1)
print df
AA BB CC DD
Index
1 1 2 3 4
2 5 6 7 8
3 9 1 2 3
这篇关于在PANDAS中删除标题的第二行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文