Why do I keep getting the AttributeError: 'Styler' object has no attribute 'render'
when trying to save my Pandas DataFrame as an image? I made a correlation matrix of the variables in a dataframe through df.corr()
and stylized it.
import pandas as pd
import dataframe_image as dfi
import imgkit
df = pd.read_excel(filename)
CM = df.corr() # CM stands for correlation matrix
styled_CM = CM.style.background_gradient(cmap="Blues")
# either of the following options:
html = styled_CM.render()
imgkit.from_string(html, 'styled_CM.png')
# or this one:
dfi.export(styled_CM, 'styled_CM.png')
Both options return the following
AttributeError: 'Styler' object has no attribute 'render'
How to work solve this or what alternative to use?
The Styler object has the to_html
property:
html = styled_CM.to_html()
instead of html = styled_CM.render()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments