Search code examples
python-3.xgoogle-sheetsgoogle-sheets-apigspread

update value in google sheet with if condition in another column using python


I have a similar data as below in google sheet. I want to update the pageId for pagename "abc".

PageName page id
xyz         24324354_a
abc         12345678_b
lmn         98765432_c

I'm able to update manually passing B3 sheet.update('B3','updated_value') but How should I get B3 by adding a if condition where pagename=abc in python code.

Need help.


Solution

  • If your provided script in your comment is used, how about the following modification?

    Modified script:

    # Your provided script in your comment.
    records_data = sheet_instance.get_all_records()
    test = sheet_instance.col_values(1)
    rownum = test.index('abc') + 1
    print(rownum)
    row = sheet_instance.row_values(rownum)
    print(row)
    
    sheet_instance.update_cell(rownum, 2, 'Updated') # Added
    
    • In this case, rownum can be directly used.

    Reference: