簡體   English   中英

如何使用xlsx中的相同列在Python中打開多個xslx文件

[英]How to open multiple xslx files in Python with the same columns from the xlsx

我做了一些調整,使代碼可以在這里工作,但是列標題最終排成一行,並且列標題應該放在哪里,我得到了列標題的數字,而不是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)

我在下面附有完整文檔的鏈接

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

我只是建議您,xlsx文件格式並不總是在熊貓上工作的最佳選擇。 我一直更喜歡在數據框中讀取數據,然后以.csv格式導出以進行進一步的分析/工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM