how to add background color tospecific dataframe column while converting to html

248 views Asked by At

Need to colour column with diff colours. Using below code but nor working getting data in mail with straight line. To html method is working properly to generate table but need diff colour to all column in Dataframe.

pdf.style.apply(highlight_cols, axis=None)

and ther one is

output=df.to_html() 
batch_name=['a','a','p','o'] 
duration=['10','45','65','20'] 
batch_dict={'Batch Name': batch_name,'Duration':duration} 
pdf = pd.DataFrame(batch_dict) 
def highlight_cols(x): 
    pdf = x.copy()   
    pdf[['Batch Name']] = 'background-color: grey'     
    print('pdf x', pdf)    
    return pdf    
1

There are 1 answers

0
AudioBubble On

def highlight_col(x): if x.name in 'B': return ['background-color: #feffc1']*x.shape[0] elif x.name in 'Duration':e return ['background-color: #ff9090']*x.shape[0] else: return ['background-color: None']*x.shape[0]

pdf=pdf.style.apply(highlight_col,axis=0).hide_index().set_table_styles(styles).set_caption('Check')