Skip to content Skip to sidebar Skip to footer

How To Use `style` In Conjunction With The `to_html` Classes On A Dataframe?

I have a DataFrame like df = pd.DataFrame(np.random.randn(10).reshape(2, 5)) df # 0 1 2 3 4 # 0 -0.067162 -0.505401 -0.019208 1.1

Solution 1:

Try this:

html = df.style.applymap(colorize) \
         .set_table_attributes('border="1" class="dataframe table table-hover table-bordered"') \
         .set_precision(3) \
         .render()

withopen('d:/temp/a2.html', 'w') as f:
    f.write(html)

Result:

enter image description here

Post a Comment for "How To Use `style` In Conjunction With The `to_html` Classes On A Dataframe?"