I am trying to combine multiple excel sheets using Python. However when I ran this script a few months ago it worked without any issues, now I am receiving the following error.
Traceback (most recent call last): File "P:\2018\218143\GIS\Working_HBK_ASE_Project\SUE_QLData\Python\SUEGISPrep.py", line 15, in data_xlsA1 = pd.read_excel(r'\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4296_LookAheadSchedule.xlsx', 'Schedule and QLA Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions) File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\pandas\util_decorators.py", line 299, in wrapper return func(*args, **kwargs) TypeError: read_excel() got an unexpected keyword argument 'headers'
here is the code...
`import pandas as pd
skprws = range(0, 3)
datatype = {"Task\nOrder": str,"Contract \nRequest\nNumber": str, "Actual \nNorthing": float, "Actual \nEasting": float, "Proposed Northing": float, "Proposed Easting": float, "Ground Elevation": float, "Top of Utility": float, "Depth": float, "Rim Elevation": float, "Depth (1)": float, "Invert (1)": float, "Depth (2)": float, "Invert (2)": float, "Depth (3)": float, "Invert (3)": float, "Depth (4)": float, "Invert (4)": float, "Depth (5)": float, "Invert (5)": float, "MP \nStart": float, "MP \nEnd": float}
conversions= {"Request #": int, "Priority": int, "SUE Contract Number": int, "Request Contract\nNumber": int, "FWAR\nNumber": int}
data_xlsA1 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4296_LookAheadSchedule.xlsx', 'Schedule and QLA Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsA2 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4297_LookAheadSchedule.xlsx', 'Schedule and QLA Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsA3 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4415_LookAheadSchedule.xlsx', 'Schedule and QLA Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsA4 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4700_LookAheadSchedule.xlsx', 'Schedule and QLA Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsA5 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\MM Formatted-LG_HBK_ARD_4570_LookAheadSchedule_02242023.xlsx', 'Schedule and QLA Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsB1 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4296_LookAheadSchedule.xlsx', 'QLB Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsB2 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4297_LookAheadSchedule.xlsx', 'QLB Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsB3 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4415_LookAheadSchedule.xlsx', 'QLB Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsB4 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4700_LookAheadSchedule.xlsx', 'QLB Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsB5 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\MM Formatted-LG_HBK_ARD_4570_LookAheadSchedule_02242023.xlsx', 'QLB Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsC1 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS`Source Data\LG_ASE_TAS_4296_LookAheadSchedule.xlsx', 'QLC Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsC2 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4297_LookAheadSchedule.xlsx', 'QLC Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsC3 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4415_LookAheadSchedule.xlsx', 'QLC Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsC4 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\LG_ASE_TAS_4700_LookAheadSchedule.xlsx', 'QLC Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
data_xlsC5 = pd.read_excel(r'\\chicagostorage2017\public\2018\218143 - ISTHA SUE\05 - GIS\05.09 - GIS Source Data\MM Formatted-LG_HBK_ARD_4570_LookAheadSchedule_02242023.xlsx', 'QLC Results', headers= 1, skiprows= skprws, index_col=None, dtype=datatype,converters=conversions)
dfA = pd.concat([data_xlsA1, data_xlsA2, data_xlsA3, data_xlsA4, data_xlsA5])
dfB = pd.concat([data_xlsB1, data_xlsB2, data_xlsB3, data_xlsB4, data_xlsB5])
dfC = pd.concat([data_xlsC1, data_xlsC2, data_xlsC3, data_xlsC4, data_xlsC5])
dfA.to_excel(r'P:\2018\218143\GIS\Data\TBL\Excel_In\LG_ASE_TAS_Combined_QLA_LookAhead.xlsx', encoding= 'utf-8', index=False)
dfB.to_excel(r'P:\2018\218143\GIS\Data\TBL\Excel_In\LG_ASE_TAS_Combined_QLB.xlsx', encoding= 'utf-8', index=False)
dfC.to_excel(r'P:\2018\218143\GIS\Data\TBL\Excel_In\LG_ASE_TAS_Combined_QLC.xlsx', encoding= 'utf-8', `your text`index=False)
print("Files Constructed")
`
I tired to change the word "headers" to "header". When I did this I didn't get an error however not all the spreadsheet ended combined. Only the first one was in the new table. I did not write this code and am very very inexperienced with programing.
1条答案
按热度按时间bxjv4tth1#
我邀请你看一下panda文档。这完全取决于你想要什么样的输出。第一个错误可以通过将header改为header来解决。第二个错误可能涉及panda.concat函数的参数。它取决于,例如,你打算用哪个轴来concat你的对象,如果你想忽略指数...然而,从我的Angular 来看,很难解决你的问题,因为没有进一步描述你的问题是什么,也没有可视化它。
以下是访问已解决错误的文档的链接:https://pandas.pydata.org/docs/reference/api/pandas.read_excel.html
如果你想以最适合你的方式理解和修改你的代码,这里有一个链接:https://pandas.pydata.org/docs/reference/api/pandas.concat.html