【发布时间】:2020-05-07 16:50:37
【问题描述】:
我正在尝试合并一个目录中的所有文件并将合并的文件保存到另一个目录中。 我正在使用 Python 3.8。 当我运行代码时,我得到以下带有 AttributeError 的信息:
c:\test\Upload test\Book1.xlsx
c:\test\Upload test\Book2.xlsx
c:\test\Upload test\Book3.xlsx
Traceback (most recent call last):
File "C:/Python/PythonDev/combine.py", line 104, in <module>
newdf.to_excel(writer,"All")
AttributeError: 'NoneType' object has no attribute 'to_excel'
代码:
import pandas as pd
import globe
filelist = glob.glob(r'c:\test\Upload test\*.xlsx')
file1 = "*.*"
for i in filelist:
file2 = pd.read_excel(i)
file2['FileName'] = i
file1 = ['newdf']
newdf = file1.append(file2)
print (i)
writer = pd.ExcelWriter(r'c:\test\Uploaded\uploadfile.xlsx', engine= 'xlsxwriter')
newdf.to_excel(writer,"All")
writer.save()
【问题讨论】:
-
抱歉错字。问题应该是“我正在尝试合并一个目录中的所有文件,然后将合并的文件保存到另一个目录中。”
-
追加不返回任何东西...
标签: python attributeerror nonetype