【问题标题】:How to open multiple xslx files in Python with the same columns from the xlsx如何在 Python 中使用 xlsx 中的相同列打开多个 xlsx 文件
【发布时间】:2017-06-10 03:23:44
【问题描述】:

我做了一些调整,我得到了可以在这里工作的代码但是列标题最终排成一行,列标题应该在哪里我得到了列标题的数字,而不是像 1、2、3.... 我会喜欢从 xlsx 文件中获取列名。代码如下:

# import modules
from IPython.display import display
import pandas as pd
import numpy as np
pd.set_option("display.max_rows", 999)
pd.set_option('max_colwidth',100)
%matplotlib inline

# filenames
file_names = ["data/OrderReport.xlsx", "data/OrderReport2.xlsx"]

# read them in
excels = [pd.ExcelFile(name) for name in file_names]

# turn them into dataframes
frames = [x.parse(x.sheet_names[0], header=None,index_col=None) for x in excels]

# concatenate them
atlantic_data = pd.concat(frames)

# write it out
combined.to_excel("c.xlsx", header=False, index=False)

【问题讨论】:

  • 有什么问题?只需使用pd.read_excel 进行迭代和导入。

标签: python excel pandas dataframe ipython-notebook


【解决方案1】:

我在下面附上了完整文档的链接

http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.read_excel.html

我只是建议您,xlsx 文件格式并不总是处理 pandas 的最佳选择。我一直更喜欢在数据框中读取数据,然后以 .csv 格式导出以供进一步分析/工作。

【讨论】:

  • 好的,我对代码做了一些调整。我得到了一个名为 atlantic_data 的合并数据框,但我对列名有疑问。感谢帮助! @Harry_pb
猜你喜欢
  • 2020-01-24
  • 2016-09-22
  • 2017-09-11
  • 1970-01-01
  • 2019-10-09
  • 2018-04-08
  • 2013-09-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多