Potential issue in Styler.to_excel() with Styler.set_properties() · Issue #30008 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
df = pd.DataFrame((np.random.rand(5, 4)*100), columns=list('ABCD'))
df_style = df.style.set_properties(**{'background-color': 'black',
'color': 'lawngreen',
'border-color': 'white'})
display(df_style)
df_style.to_excel('test.xlsx')
Problem description
I was using the Styler.set_properties() function to format the Pandas Dataframe, while it (df_style) shows up nicely in Jupyter Notebook, it caused an error in the Styler.to_excel() function. Could you please advise how I can fix it?
[Issue also posted in stackoverflow.com: https://stackoverflow.com/questions/59161827/error-in-pandas-styler-set-properties-with-styler-to-excel\]
Expected Output
Error in Styler.to_excel():
TypeError: tuple indices must be integers or slices, not dict
Output of pd.show_versions()
[paste the output of pd.show_versions()
here below this line]
INSTALLED VERSIONS
commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-1054-aws
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.25.3
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.8.0
pip : 19.3.1
setuptools : 42.0.1.post20191125
Cython : 0.29.14
pytest : 5.3.0
hypothesis : None
sphinx : 2.2.1
blosc : None
feather : None
xlsxwriter : 1.2.6
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : 2.10.3
IPython : 7.9.0
pandas_datareader: None
bs4 : 4.8.1
bottleneck : 1.3.1
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.1
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.11
tables : 3.6.1
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.6