I created a dictionary of pandas dataframe:
d[k] = pd.DataFrame(data=data[i])
So I assume that d[k]
is a correct pandas dataframe.
Then
for k in d.keys():
d[k].to_excel (file_name)
Then I have the error:
TypeError: got invalid input value of type <class 'xml.etree.ElementTree.Element'>, expected string or Element
I am using Python 3.7, pandas 0.25.3.
Update: if I replace to_excel
by to_csv
, the code runs perfectly.
Side issue: in constant_memory mode XlsxWriter requires that data in written in row x column order but the Pandas Excel writer works in column x row order. So I wonder if the constant_memory option is actually getting passed or if the dataframe is actually being written correctly. .to_excel only takes columns that are type: object.
Read an Excel file into a pandas DataFrame. Read a comma-separated values (csv) file into DataFrame. For compatibility with to_csv () , to_excel serializes lists and dicts to strings before writing. Once a workbook has been saved it is not possible to write further data without rewriting the whole workbook. To specify the sheet name:
Deprecated since version 1.2.0: As the xlwt package is no longer maintained, the xlwt engine will be removed in a future version of pandas. Write MultiIndex and Hierarchical Rows as merged cells.
I have same problem with openpyxl=3.0.2
,
Refer to this answer, I roll openpyxl back to 3.0.1(conda or pip) and it works.
>>> conda remove openpyxl
>>> conda install openpyxl==3.0.1
or
>>> pip uninstall openpyxl
>>> pip install openpyxl==3.0.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With