如何通过Python API在一个Google电子表格中更新多个工作表

如何通过Python API在一个Google电子表格中更新多个工作表,python,pandas,google-python-api,Python,Pandas,Google Python Api,目前,我正在将数据帧(Python/Pandas)发送到Google电子表格,目前我正在将一个数据帧推送到一个Google电子表格 我的代码是文档中的标准代码,如下所示: from gspread_dataframe import get_as_dataframe, set_with_dataframe import gspread from oauth2client.service_account import ServiceAccountCredentials scope = ['http

目前,我正在将数据帧(Python/Pandas)发送到Google电子表格,目前我正在将一个数据帧推送到一个Google电子表格

我的代码是文档中的标准代码,如下所示:

from gspread_dataframe import get_as_dataframe, set_with_dataframe
import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
google_client = gspread.authorize(creds)
sheet = google_client.open('User IDs').sheet1
我的问题是:如果我想在同一个谷歌电子表格上将多个数据帧推送到多个工作表上,我可以吗

注意:我知道我可以制作单独的Google电子表格来保存多个数据帧,但我希望能够有一个包含多个表格的电子表格

谢谢

谷歌将谷歌电子表格中的“选项卡”称为“工作簿”

您需要做的只是:

sheet1 = google_client.open('User IDs').workbook('sheet1')
sheet2 = google_client.open('User IDs').workbook('sheet2')
...
sheet_n = google_client.open('User IDs').workbook('sheet_n')
其中“sheet1”…“sheet_n”是电子表格“用户ID”中工作簿的名称

然后。。。您可以通过以下方式将数据推送到电子表格:

set_with_dataframe(WORKBOOK_NAME, DATAFRAME_NAME)
*假设您使用的是gspread_数据帧模块