python pandas 如何读取没有未命名列的 excel 文件

How can python pandas read excel file without unnamed columns

我想使用 python pandas 阅读 .xlsx。问题是在 excel 文件的开头,它有一些额外的数据,例如 table 和 tables 内容的标题或描述。这引入了未命名的列,因为 pandas DataReader 将其作为列。 但是 tables 内容在几行之后开始。

A                              B                     C
this is description
last updated: Mar 18th,2014
                               Table content
Country                        Year                 Product_output
Canada                         2017                 3002
Bulgaria                       2016                 2201
...

table 内容从第 4 行开始。列必须是 "Country"、"year"、"proudct_output" 而不是 "this is description"、"unnamed" , "unnamed"。

当您使用 read_excel 函数时,将 skiprows 参数设置为 3。

尝试使用 index_col=[0] 参数 pd.read_excel('Excel_Sample.xlsx',sheet_name='Sheet1',index_col=[0])