Sending dataframe to a worksheet within a Google Sheet document

161 views Asked by At

I am using the below code to send df to a google sheet. Data is being exported to sheet1 within google sheets. Is there a way how I can modify my code to send another dataframe to sheet2 within the same google worksheet?

gc = pygsheets.authorize(service_file)
df = df.values.tolist()
sh = gc.open_by_url(sheet_url)
wks = sh[0]
wks.update_cells(crange='A2',values = df)

I tried copying sheet2 url but when I run my code data is still being exported to sheet1.

1

There are 1 answers

1
Zanshin On

Something like this probably;

sh_2 = gc.open_by_url(sheet_url_2)
wks_2 = sh_2[0]
wks_2.update_cells(crange='A2',values = df_2)