【发布时间】:2020-07-22 18:50:55
【问题描述】:
我几乎完成了在 python 中将 excel 文件与 pandas 合并,但是当我给出路径时它不会工作。我得到错误''没有这样的文件或目录:'file1.xlsx'''。当我将路径留空时,它可以工作,但我想决定它应该从哪个文件夹中获取文件。并且我将文件保存在“excel”文件夹中
cwd = os.path.abspath('/Users/Viktor/downloads/excel') #If i leave it empty and have files in /Viktor it works but I have the desired excel files in /excel
print(cwd)
files = os.listdir(cwd)
df = pd.DataFrame()
for file in files:
if file.endswith('.xlsx'):
df = df.append(pd.read_excel(file), ignore_index=True)
df.head()
df.to_excel(r'/Users/Viktor/Downloads/excel/resultat/merged.xlsx')
【问题讨论】: