Reputation: 2475
I'm using Pandas version 0.16.2 and openpyxl version 2.2.4 in python-3.3. I am trying to write a pretty simple pandas dataframe containing floats, strings and NaNs. When I use the code:
import pandas as pd
writer = pd.ExcelWriter(xls_path)
df.to_excel(writer,'sheet1')
writer.save()
I get the error:
TypeError Traceback (most recent call last)
<ipython-input-3-2349bf9de8ec> in save_xls(list_dfs, xls_path, sheetnames)
5 import pandas as pd
6 writer = pd.ExcelWriter(xls_path)
----> 7 df.to_excel(writer,sheetnames[n])
8
9 writer.save()
/Users/dylan/Virtualenvs/ve33/lib/python3.3/site-packages/pandas/core/frame.py in to_excel(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, encoding, inf_rep)
1272 formatted_cells = formatter.get_formatted_cells()
1273 excel_writer.write_cells(formatted_cells, sheet_name,
-> 1274 startrow=startrow, startcol=startcol)
1275 if need_save:
1276 excel_writer.save()
/Users/dylan/Virtualenvs/ve33/lib/python3.3/site-packages/pandas/io/excel.py in write_cells(self, cells, sheet_name, startrow, startcol)
776
777 if style_kwargs:
--> 778 xcell.style = xcell.style.copy(**style_kwargs)
779
780 if cell.mergestart is not None and cell.mergeend is not None:
/Users/dylan/Virtualenvs/ve33/lib/python3.3/site-packages/openpyxl/compat/__init__.py in new_func(*args, **kwargs)
65 lineno=_code.co_firstlineno + 1
66 )
---> 67 return obj(*args, **kwargs)
68 return new_func
69
TypeError: copy() got an unexpected keyword argument 'font'
Any help on what could be going wrong?
Thanks!
Upvotes: 0
Views: 5271
Reputation: 24742
Can you provide a way to reproduce the error? I use Python 3.4, pandas 0.16.2 with excel writer engine openpyxl
. The following sample code works perfectly on my PC.
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(1000, 3))
xlsx_path = 'my_excel_file.xlsx'
writer = pd.ExcelWriter(xlsx_path)
df.to_excel(writer, 'Sheet1', engine='openpyxl')
Upvotes: 1