pandas read_excel删除空标题下的列 [英] Pandas read_excel removes columns under empty header
问题描述
我有一个Excel文件,其中A1,A2,A3为空,但A4:A53包含列名.
I have an Excel file where A1,A2,A3 are empty but A4:A53 contains column names.
在"R"中,当您读取数据时,A1,A2,A3的列名称将为"X_1,X_2,X_3",但是当使用pandas.read_excel
时,它仅跳过前三列,因此将其忽略.问题在于每个文件中的列数是动态的,因此我无法解析列范围,也无法编辑文件并为A1,A2,A3添加虚拟名称"
In "R" when you were to read that data, the columns names for A1,A2,A3 would be "X_1,X_2,X_3" but when using pandas.read_excel
it simply skips the first three columns, thus ignoring them. The problem is that the number of columns in each file is dynamic thus I cannot parse the column range, and I cannot edit the files and adding "dummy names" for A1,A2,A3
推荐答案
使用参数skip_blank_lines = False,如下所示:
Use parameter skip_blank_lines=False, like so:
pd.read_excel('your_excel.xlsx', header=None, skip_blank_lines=False)
这个stackoverflow问题(最终)为我指明了正确的方向: Python熊猫read_excel无法识别空单元格
This stackoverflow question (finally) pointed me in the right direction: Python Pandas read_excel doesn't recognize null cell
pandas.read_excel文档不要因为它是关键字之一,所以不包含有关此信息的任何信息,但是您可以在以下常规io文档中找到它:
The pandas.read_excel docs don't contain any info about this since it is one of the keywords, but you can find it in the general io docs here: http://pandas.pydata.org/pandas-docs/stable/io.html#io-read-csv-table
这篇关于 pandas read_excel删除空标题下的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!