Я хочу объединить файлы .xlsx в один документ .xlsx, но сохранить на отдельных листах в этом документе.
Я получаю сообщение об ошибке «ValueError: недостаточно значений для распаковки (ожидается 2, получено 1)»
Благодаря устранению неполадок я прочитал, что это может быть связано с тем, что в файлах .xlsx есть объединенные ячейки. Я отбросил оскорбительные слияния, но все равно не повезло.
number = 1
writer = pd.ExcelWriter("P&L Detail Combined.xlsx", engine = 'xlsxwriter')
for files in os.listdir(directory):
if files.endswith(".xlsx"):
df = pd.read_excel(files, index_col = 0)
df = df.drop([-2,4])
numstr = str(number)
sheetnum = "GMCO Q" + numstr
df.to_excel(writer, sheet_name = sheetnum, index=False)
number =+ 1
writer.save()
else:
continue
Желаемый результат - объединенный файл с данными на отдельных листах.
Редактировать ::
Traceback (most recent call last):
File "Combine_to_tabs.py", line 12, in <module>
df = pd.read_excel(files, index_col = 0)
File "/Applications/anaconda/lib/python3.6/site-packages/pandas/io/excel.py", line 200, in read_excel
io = ExcelFile(io, engine=engine)
File "/Applications/anaconda/lib/python3.6/site-packages/pandas/io/excel.py", line 257, in __init__
self.book = xlrd.open_workbook(io)
File "/Applications/anaconda/lib/python3.6/site-packages/xlrd/__init__.py", line 422, in open_workbook
ragged_rows=ragged_rows,
File "/Applications/anaconda/lib/python3.6/site-packages/xlrd/xlsx.py", line 833, in open_workbook_2007_xml
x12sheet.process_stream(zflo, heading)
File "/Applications/anaconda/lib/python3.6/site-packages/xlrd/xlsx.py", line 553, in own_process_stream
self.do_merge_cell(elem)
File "/Applications/anaconda/lib/python3.6/site-packages/xlrd/xlsx.py", line 609, in do_merge_cell
first_cell_ref, last_cell_ref = ref.split(':')
ValueError: not enough values to unpack (expected 2, got 1)