简体   繁体   English

pandas.read_excel,第一行值

[英]pandas.read_excel, first row values

I am trying to get the first row from an excel file using pandas.read_excel.我正在尝试使用 pandas.read_excel 从 excel 文件中获取第一行。 The issue that I have is that Pandas uses the first row values as labels for the data frame.我遇到的问题是 Pandas 使用第一行值作为数据框的标签。 Is there a way of having them - say - in a list?有没有办法让它们——比如说——放在一个列表中?

I have tried to see if there is an option for pandas.read_excel in order to not load the first row as a label but I haven't found anything ( http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html ).我试图看看是否有 pandas.read_excel 的选项,以便不将第一行作为标签加载,但我什么也没找到( http://pandas.pydata.org/pandas-docs/stable/generated /pandas.read_excel.html )。

I know that I can get the same result using other libraries (ie xlrd, openpyxl, ..).我知道我可以使用其他库(即 xlrd、openpyxl、..)获得相同的结果。 However, if it is possible, I would like to use pandas.read_excel, in order to follow the same approach that I have used already for other sheets in the same python file and to better understand the library.但是,如果可能的话,我想使用 pandas.read_excel,以便遵循我已经用于同一个 python 文件中的其他工作表的相同方法,并更好地理解该库。

IIUC, if you have an excel spreadsheet called 'Workbook.xlsx' like: IIUC,如果您有一个名为“Workbook.xlsx”的 Excel 电子表格,例如:

1 2
2 3
3 4

you can read it with:你可以阅读它:

df = pd.read_excel('Workbook1.xlsx', header=None)

the header=None option let you skip the first line as header keeping it as it is. header=None选项让您跳过第一行作为标题保持原样。 This returns:这将返回:

   0  1
0  1  2
1  2  3
2  3  4

Hope that helps.希望有帮助。

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

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