【发布时间】:2020-12-21 15:54:48
【问题描述】:
这是我的代码的简化示例和我想在谷歌电子表格中获得的结果的屏幕截图。我希望将数据框样式保存到谷歌电子表格中,就像使用 python 将表格样式应用于 excel 一样。 或者使用 gspread-formatting 当值高于阈值时高亮单元格背景。
谁能给我一个例子如何做到这一点? 谢谢!
cars = {'Brand': ['Honda Civic','Ferrari','Toyota Corolla','Ford Focus','Audi A4','TESLA','Ford Fusion','BENZ'],
'Price': [22000,625000,25000,27000,35000,55000,28000,51000]}
df_car = pd.DataFrame(cars, columns = ['Brand', 'Price'])
def _color_if_above_budget(s):
return ['background-color: red' if val >50000 else '' for val in s]
s=df_car.style.apply(_color_if_above_budget, subset=['Price'])
ws=**worksheet
gd.set_with_dataframe(worksheet=ws,dataframe=df_car,include_index=False,include_column_header=True,resize=True)
【问题讨论】:
标签: python pandas google-sheets google-sheets-api gspread