0

I'm trying to upload my code that applies conditional formatting to an Excel file using pandas dataframe values on a google sheets file.

For that I have the following code:

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})

Using Pandas DataFrame Excel Write I was able to run my code without any problems but the same approach it doesn't work using pygsheets. Anyone knows how can I apply this conditional formatting using pygsheets?

Thanks!

Pedro Alves
  • 1,004
  • 1
  • 21
  • 47
  • 1
    always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Dec 26 '20 at 17:07

1 Answers1

0

Please use wks.add_conditional_formatting for applying conditional formatting. Note that since this is not yet released in pypi so use the staging version.

pip install --upgrade https://github.com/nithinmurali/pygsheets/archive/staging.zip

see doc here. and also see examples in readme.

Nithin
  • 5,470
  • 37
  • 44