Extracting Excel sheet's style and applying it on Pandas DataFrame

Viewed 446

I've been looking around, however, it seems that this question was not asked yet.

Is there a way to get Excel's sheet style format and apply it on a Pandas DataFrame, respecing the shape of the DataFrame and replicating completely?

Example:

enter image description here

Thanks!

UPDATE: While going through style documentation I've noticed that there is:

from pandas.io.formats.style import Styler
EasyStyler = Styler.from_custom_template("templates", "myhtml.tpl")
HTML(EasyStyler(df3).render(table_title="Another Title"))

After exporting Excel to HTML I've attempted to perform this, however, was unsuccessful.

2 Answers

Pandas is not pretty good with styling, I think a better option would be openpyxl

That's if you want to save it as an excel file, then you can define the styles with openpyxl

If you want to display a dataframe with styles, that's not possible.

from openpyxl import styles
from openpyxl.styles import Color, PatternFill, Font, Border

There is no way to do this with pandas specifically. You would have to get to the reading of the raw excel data and parse the xml-ish format that it comes in and then recreate the styling you want.

Related