My code:
def write_excel(filename, sheetname, dataframe):
with pd.ExcelWriter(filename, engine='openpyxl', mode='a') as writer:
workBook = writer.book
try:
workBook.remove(workBook[sheetname])
except:
print("Worksheet does not exist")
finally:
dataframe.to_excel(writer, sheet_name=sheetname, index=False)
writer.save()
write_excel(r"C:UsersHarshadDocumentsProjectFilesBacktest.xlsx", '888', df_normalized)
Error at:
write_excel(r"C:UsersHarshadDocumentsProjectFilesBacktest.xlsx", '888', df_normalized)
I am getting at error as:
Traceback (most recent call last):
File "C:/Users/Harshad/Documents/Project/Code/Step-4-Normalizing 888Sport Odds.py", line 66, in <module>
write_excel(r"C:UsersHarshadDocumentsProjectFilesBacktest.xlsx", '888', df_normalized)
File "C:/Users/Harshad/Documents/Project/Code/Step-4-Normalizing 888Sport Odds.py", line 55, in write_excel
with pd.ExcelWriter(filename, engine='openpyxl', mode='a') as writer:
File "C:UsersHarshadPycharmProjectsSelf Projectvenvlibsite-packagespandasioexcel\_openpyxl.py", line 25, in __init__
book = load_workbook(self.path)
File "C:UsersHarshadPycharmProjectsSelf Projectvenvlibsite-packagesopenpyxl
eaderexcel.py", line 315, in load_workbook
reader.read()
File "C:UsersHarshadPycharmProjectsSelf Projectvenvlibsite-packagesopenpyxl
eaderexcel.py", line 280, in read
self.read_worksheets()
File "C:UsersHarshadPycharmProjectsSelf Projectvenvlibsite-packagesopenpyxl
eaderexcel.py", line 266, in read_worksheets
pivot = TableDefinition.from_tree(tree)
File "C:UsersHarshadPycharmProjectsSelf Projectvenvlibsite-packagesopenpyxldescriptorsserialisable.py", line 83, in from_tree
obj = desc.from_tree(el)
File "C:UsersHarshadPycharmProjectsSelf Projectvenvlibsite-packagesopenpyxldescriptorssequence.py", line 85, in from_tree
return [self.expected_type.from_tree(el) for el in node]
File "C:UsersHarshadPycharmProjectsSelf Projectvenvlibsite-packagesopenpyxldescriptorssequence.py", line 85, in <listcomp>
return [self.expected_type.from_tree(el) for el in node]
File "C:UsersHarshadPycharmProjectsSelf Projectvenvlibsite-packagesopenpyxldescriptorsserialisable.py", line 103, in from_tree
return cls(**attrib)
File "C:UsersHarshadPycharmProjectsSelf Projectvenvlibsite-packagesopenpyxlpivotable.py", line 601, in __init__
self.x = x
File "C:UsersHarshadPycharmProjectsSelf Projectvenvlibsite-packagesopenpyxldescriptorssequence.py", line 25, in __set__
raise TypeError("Value must be a sequence")
TypeError: Value must be a sequence
This code worked till yesterday. How can I resolve it?
Thanks
question from:
https://stackoverflow.com/questions/66057374/python-typeerror-value-must-be-a-sequence 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…