删除python中的第一个标题行

问题描述 投票:1回答:1

我试图删除表格的第一个标题行,即'表2 .......'。

我试过下面的代码

d1t2.columns = d1t2.iloc[0]
d1t2 = data1t2.reindex(d1t2.index.drop(0)).reset_index(drop=True)
d1t2.columns.name = None 
d1t2

但结果是:表格的第二行,其中index=0的行已被删除。

python pandas dataframe
1个回答
3
投票

你很亲密:

d1t2.columns = d1t2.iloc[0]
d1t2.columns.name=None
d1t2.drop(0, axis=0, inplace=True)

但是,如果您从文件中读取d1t2,最好跳过第一行。

© www.soinside.com 2019 - 2024. All rights reserved.