我有以下DataFrame:
actor Daily Total actor1 actor2
Day
2019-01-01 25 10 15
2019-01-02 30 15 15
Avg 27.5 12.5 15.0
在写入电子表格的工作表时,如何更改整个“平均”行的颜色?我怎样才能突出它?
有同样的问题,并找到答案(从2019年)。我们可以使用gspread-formatting。
pip install gspread-formatting
from gspread_formatting import *
假设我们已经从电子表格中获得了工作表wks
fmt = cellFormat(
backgroundColor=color(1, 1, 0), #set it to yellow
textFormat=textFormat(foregroundColor=color(1, 0, 0)),
)
#red: (1,0,0), white: (1,1,1)
row = 3
format_cell_range(wks, rowcol_to_a1(row,1)+':' + rowcol_to_a1(row, wks.col_count), fmt)
如果我们要突出显示文本,请修改cellFormat中的代码
fmt = cellFormat(
backgroundColor=color(1, 1, 0), #set it to yellow
textFormat=textFormat(foregroundColor=color(1, 0, 0)),
)