I'm trying to append new Excel sheet (pandas dataframe) to existing file. I have tried several solutions, but I keep getting the same error:
/usr/local/lib/python3.7/dist-packages/openpyxl/descriptors/serialisable.py in to_tree(self, tagname, idx, namespace)
147 continue
148 else:
--> 149 node = obj.to_tree(child_tag)
150 if node is not None:
151 el.append(node)
AttributeError: 'str' object has no attribute 'to_tree'
The line that causes the error is writer.save():
file_name = path_to_file
key = 'name'
writer = pd.ExcelWriter(file_name, engine='openpyxl')
if os.path.exists(file_name):
book = openpyxl.load_workbook(file_name)
writer.book = book
df_times.to_excel(writer, sheet_name=key)
writer.save()
writer.close()
I couldn't find any good solution/explanation online for that.
I am looking for an idea for how to do it, or avoid this error. I have tried the solutions here: How to save a new sheet in an existing excel file, using Pandas?