1

需要用不同的颜色为列着色。使用下面的代码,但也不能用直线在邮件中获取数据。To html 方法可以正常工作以生成表格,但需要对 Dataframe 中的所有列进行差异颜色。

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

还有一个是

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    
4

1 回答 1

0

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')

于 2020-09-08T10:40:12.543 回答