【发布时间】:2020-12-26 11:36:39
【问题描述】:
我正在尝试上传我的代码,该代码使用谷歌表格文件上的熊猫数据框值将条件格式应用于 Excel 文件。
为此,我有以下代码:
import pygsheets
import pandas as pd
gc = pygsheets.authorize(service_file="")
wsh = gc.open_by_url('')
sheet = wsh[0]
my_formats = {}
for index, row in df.iterrows():
if 'PC' in row['ID']:
my_formats['"' + row['ID'] + '"'] = '#C00000'
else:
my_formats['"' + row['ID'] + '"'] = '#010203'
sheet.set_dataframe(df, 'A2')
for val, color in my_formats.items():
fmt = wsh.add_format({'bold':True,'font_color': color})
wsh.conditional_format('F2:F50000', {'type': 'cell',
# 'bold': True,
'criteria': '=',
'value': val,
'format': fmt})
使用 Pandas DataFrame Excel Write 我能够毫无问题地运行我的代码,但使用 pygsheets 的方法相同。任何人都知道如何使用 pygsheets 应用这种条件格式?
谢谢!
【问题讨论】:
-
总是将完整的错误消息(从单词“Traceback”开始)作为文本(不是屏幕截图)放在有问题的(不是评论)中。还有其他有用的信息。
标签: python google-sheets conditional-formatting pygsheets