我只需要有关如何解决问题的建议。我需要为一个Excel文件的每个电子表格创建一个新文件(该文件大约有80张),其中包含相应的电子表格数据。
是否可以使用xlrd库执行类似的操作?
答案 0 :(得分:0)
好的,这是一种解决方法
import pandas as pd
df1 = pd.read_excel('C:\\Users\\xy\\Desktop\\Report.xls', 'Sheet 1',decimal=',')
df2 = pd.read_excel('C:\\Users\\xy\\Desktop\\Report.xls', 'Sheet 2',decimal=',')
df3 = pd.read_excel('C:\\Users\\xy\\Desktop\\Report.xls', 'Sheet 3',decimal=',')
df4 = pd.read_excel('C:\\Users\\xy\\Desktop\\Report.xls', 'Sheet 4',decimal=',')
df5 = pd.merge(df1, df2, df3, df4)
答案 1 :(得分:0)
您可以使用Pandas
库解决问题:
#Import pandas module (if you don't have it open the command line and run: pip install pandas)
import pandas as pd
#Read the Excel file to a Pandas DataFrame
#Note: change "file_name" to the name of your Excel file
#This will give you a dictionary containing one DataFrame per each sheet on the Excel file
data = pd.read_excel("file_name.xlsx", sheet_name=None)
#Iterate through the dictionary
count = 0
for d in data:
#Give different names according to the sheet where data came from
count = count + 1
name = "sheet_" + str(count)
#Save to an Excel file
d.to_excel(name + ".xlsx")