📅  最后修改于: 2022-03-11 14:45:44.932000             🧑  作者: Mango
import numpy as np
import pandas as pd
df = pd.DataFrame([[8484,-1.15],[1390,3.5],[327,10.5],[1135,3.3],[6499,2.0],[1055,4.0]], columns=['data1','dat2'])
def color_rule(val):
return ['background-color: red' if x >= 3 else 'background-color: yellow' for x in val]
html_column = df.style.apply(color_rule, axis=1, subset=['dat2'])
html_column.to_excel('styled.xlsx', engine='openpyxl')
html_column