【问题标题】:Reading formatted excel file in Python在 Python 中读取格式化的 excel 文件
【发布时间】:2018-06-29 12:02:30
【问题描述】:

我在使用 pandas 读取 xlsx 文件时遇到问题。该文件格式轻微。以下是文件 - sample.xlsx

我在 Python3 中使用以下代码:

>>> import pandas as pd
>>> file = pd.ExcelFile('sample.xlsx')
>>> file.sheet_names
>>> temp = file.parse('Named Insured')
>>> temp.shape

形状显示为 740,10,而原始文件则完全不同。提取出来的数据也是乱七八糟的。

【问题讨论】:

  • 你的答案不是很明确。有什么不同吗?究竟什么是混乱的?如果您的意思是第一行看起来很模糊,那么您可能不想要第一行,因为它们没有被列出。这可以通过以下方式解决: temp = file.parse('Named Insured', skiprows = 3, header = 0)
  • 尝试打印 temp.head() 并将其与原始文件匹配。不一样。

标签: python python-3.x pandas


【解决方案1】:

文件为 2007-2013 Excel XML 格式(根据 LibreOffice

pandas.read_excel() 不起作用,请参阅Read Excel XML .xls file with pandas 以了解问题的分析和可能的解决方案...

(https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html)

【讨论】:

  • sample.xlsx:1:2: 格式不正确(无效令牌)
猜你喜欢
  • 2021-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-20
  • 2022-06-16
  • 2016-12-26
  • 1970-01-01
  • 2013-08-03
相关资源
最近更新 更多