更多颜色请参考:https://www.sioe.cn/yingyong/yanse-rgb-16/
效果图:
示例程序
import pandas as pd
import numpy as np
def set_row_background_css(row):
row_number = row.name
if row_number == 0: # 第一行设置CornflowerBlue 矢车菊的蓝色..
_css = 'background-color: #6495ED'
elif row_number == 4: # 第5行设置橘黄色
_css = 'background-color: orange'
else:
_css = None
return [_css] * len(row)
df = pd.DataFrame(np.random.random(size=(10, 5)))
df.style.apply(set_row_background_css, axis=1).to_excel("设置指定行的背景色.xlsx")