'Format pandas table and save as pic

Trying to creat formatted data frame and save as pic And want it in special style, But I don't know how.

import pandas as pd
import dataframe_image as dfi
from  matplotlib.colors import LinearSegmentedColormap

d = {'index': ['23.01.2022', '22.01.2022','21.01.2022','20.01.2022','total'], 
     'col1': [1,2,3,4,10],
     'col2': [100,200,300,400,1000],
    'col3': [10,20,30,40,100],
    }
df = pd.DataFrame(data=d).set_index('index')

c = ["red","tomato","coral","lightcoral","yellow", "palegreen","green","darkgreen"]
v = [0,.15,.3,.4,.5,0.6,.9,1.]
l = list(zip(v,c))
cmap=LinearSegmentedColormap.from_list('rg',l, N=256)

test = df.style.format({"col1": "{:20,.0f}", 
                          "col2": "{:20,.0f}", 
                          "col3":"{0:.1f}%"})\
                 .hide_index()\
                 .bar(subset=pd.IndexSlice[df.index!='total',["col2",]], color='#FFA07A')\
                 .background_gradient(cmap=cmap,subset=pd.IndexSlice[df.index!='total',['col1','col3',]])\
                 .set_properties(**{'text-align': 'center'})

dfi.export(test,img_path)

What I have:

enter image description here

What I want to have:

enter image description here

Does anybody know how to do this?:)

Maybe not exactly like this but with distance between columns/rows



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source