Skip to content
Advertisement

How to update google sheet with new outcome every time python script runs?

I have a python script with each time running ,it returns a new value. Then I need to add those values to a google sheet. So every day the outcome of the scripts will be added to a new row. I tried to use “pygsheet” lib but I can not handle the addition to new row for each day. How can I add the data to the last empty row?

Advertisement

Answer

There are multiple ways to achieve this using pygsheets. insert_rows can achieve this in a single line.

wks.insert_rows(wks.rows, values=[daily_value], inherit=True) # here wks is the worksheet object

If you dont want to add a new row or want to add value in a non-last row you can use append_table, assuming this is the only data in the sheet. Here you have to make sure your sheet have enough rows to fit new value.

wks.append_table(values=[daily_value])
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement