简体   繁体   English

python熊猫读取excel文件

[英]python pandas reading excel file

I have a xlsx file which has headers in column A and values in columns B through Z. How do I use pandas to read the excel file so that it reads the column names from column A and fills those columns with values from columns B through Z. 我有一个xlsx文件,该文件的A列中的标题和B到Z列的值。如何使用熊猫读取excel文件,以便它从A列读取列名,并用B到Z列的值填充这些列。

Right now when I try to read the excel file it uses the top row value in columns A through Z as column names and uses the values in row second and on for filling the columns. 现在,当我尝试读取excel文件时,它使用A到Z列中的第一行值作为列名,并使用第二行及以后的值填充列。

you can do it this way: 您可以这样操作:

In [8]: df = pd.read_excel(fn, header=None, index_col=0).T

In [9]: df
Out[9]:
0  col1  col2  col3   col4
1     1    10   100   1000
2    11   101  1001  10001

Source Excel file: Excel源文件:

在此处输入图片说明

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

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