我有大量 xls 和 xlsx 文件,我想将它们全部复制到一个新文件夹中并以 xlsx 格式复制...我做到了(将所有文件都放在 xlsx 格式的新文件夹中)但最后我在终端出错....为什么会这样?怎么解决呢?
import os
here_path= os.getcwd()
final_directory = os.path.join(here_path, r'all_xlsx')
if not os.path.exists(final_directory):
os.makedirs(final_directory)
import pandas as pd
for r, d, f in os.walk(here_path):
for file in f:
if '.xls' in file:
df = pd.read_excel(file)
print(df)
name_fil=os.path.splitext(file)[0]
writer = pd.ExcelWriter(final_directory+"/"+name_fil+".xlsx", engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')
writer.save()
错误是:
[1599 rows x 29 columns]
Traceback (most recent call last):
File "a2_all_to_xlsx_folder.py", line 38, in <module>
df = pd.read_excel(file)
File "/usr/local/lib/python3.8/dist-packages/pandas/util/_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/pandas/io/excel/_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "/usr/local/lib/python3.8/dist-packages/pandas/io/excel/_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "/usr/local/lib/python3.8/dist-packages/pandas/io/excel/_xlrd.py", line 22, in __init__
super().__init__(filepath_or_buffer)
File "/usr/local/lib/python3.8/dist-packages/pandas/io/excel/_base.py", line 353, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "/usr/local/lib/python3.8/dist-packages/pandas/io/excel/_xlrd.py", line 37, in load_workbook
return open_workbook(filepath_or_buffer)
File "/home/kubdim/.local/lib/python3.8/site-packages/xlrd/__init__.py", line 111, in open_workbook
with open(filename, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: '1_ëÇÆ_Åä11 öôæêëåæ Çéùéåæ (çäæå 113)_éäî (ïä äïÅ.)_üÅ.xlsx'