how to wrap multi index dataframe with box borders?

Viewed 28

i have a multi index dataframe on which im performing some data manipulation and in the end i need to save it as multi index dataframe with every cell in df wrapped with box borders. Here is a sample excel file from which i read df - > enter image description here

I'll skip part with data manipulation and paste only the read/save code.

When i try to save dataframe, than only the index columns and header is wrapped with borders but the rest of the table is not:

import pandas as pd
from styleframe import StyleFrame, Styler, utils 

df = pd.read_excel(full_path, index_col=[0,1,2,3])
with pd.ExcelWriter(output_path) as writer:
    df.to_excel(writer, index_label=['Main-Topic Nr.', 'Type of Topic', 'Sub-Topic Nr.','Description of Topic'])

enter image description here

I also tried to use styleframe as it can wrap df with box borders but it only works with "normal" non-multi index df. Here is what i tried:

import pandas as pd
from styleframe import StyleFrame, Styler, utils 

df = pd.read_excel(full_path, index_col=[0,1,2,3])
with pd.ExcelWriter(output_path) as writer: 
    default_style = Styler(font=utils.fonts.calibri, font_size=11)
    sf = StyleFrame(df, styler_obj=default_style) 
    header_style = Styler(bold=True, font_size=11, bg_color=utils.colors.grey)
    sf.apply_headers_style(styler_obj=header_style)
    sf.to_excel(writer)

Output:

enter image description here

How to get df wrapped with borders so the output is as hown below:

enter image description here

0 Answers
Related