Export styled pandas df with bar charts as png

412 Views Asked by At

I would like to export a pandas df with barcharts (https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html#Bar-charts) using imgkit as follows but the barcharts are not included in the final pdf.

enter image description here

I tried to pass the css separately to webkit with the css=<filename> kwarg without success. Other styled pd.DataFrames from the style manual seem to work.

Does anybody see why the CSS is not applied? Any alternatives to export styled tables to png?

import pandas as pd
import numpy as np

np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
               axis=1)
df.iloc[3, 3] = np.nan
df.iloc[0, 2] = np.nan

s = df.style.bar(subset=['A', 'B'], align='mid', color=['#d65f5f', '#5fba7d'])
html = s.render()

import imgkit
imgkit.from_string(html, 'styled_table3.png')
0

There are 0 best solutions below