简体   繁体   English

需要帮助来解决Unnamed并在熊猫的dataframe中进行更改

[英]Need help to solve the Unnamed and to change it in dataframe in pandas

how set my indexes from "Unnamed" to the first line of my dataframe in python 如何将我的索引从“未命名”设置为python中数据框的第一行

import pandas as pd

df = pd.read_excel('example.xls','Day_Report',index_col=None ,skip_footer=31 ,index=False)

df = df.dropna(how='all',axis=1)
df = df.dropna(how='all')
df = df.drop(2)

To set the column names (assuming that's what you mean by "indexes") to the first row, you can use 要将列名(假设这就是“索引”的意思)设置为第一行,可以使用

df.columns = df.loc[0, :].values

Following that, if you want to drop the first row, you can use 之后,如果要删除第一行,则可以使用

df.drop(0, inplace=True)

Edit 编辑

As coldspeed correctly notes below, if the source of this is reading a CSV, then adding the skiprows=1 parameter is much better. 正如Coldspeed在下面正确指出的那样,如果此源是读取CSV,则添加skiprows=1参数会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM