[英]How to update multiple sheets within one Google Spreadsheet via Python API
Currently I am sending DataFrames (Python/Pandas) to a Google Spreadsheet via gspread-dataframe Currently I'm pushing one DataFrame to One Google Spreadsheet. 目前,我正在通过gspread- dataframe将DataFrames(Python / Pandas)发送到Google Spreadsheet。目前,我正在将一个DataFrame推送到一个Google Spreadsheet。
my code is standard via the documentation, and looks like this: 我的代码通过文档是标准的,看起来像这样:
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
My question: If I wanted to push multiple dataframes to multiple sheets on the same Google Spreadsheet, could I? 我的问题:如果我想将多个数据框推送到同一Google Spreadsheet上的多个表上,可以吗?
Note: I know I can make Separate Google Spreadsheets to hold Multiple DataFrames, but I would like to be able to have one Spreadsheet with Multiple sheets contained within it. 注意:我知道我可以制作单独的Google Spreadsheets来容纳多个DataFrame,但是我希望能够拥有一个Spreadsheet,其中包含多个工作表。
Thank you 谢谢
Google refers to "tabs" within Google Spreadsheets as "workbooks". Google在Google Spreadsheets中将“标签”称为“工作簿”。
All you need to do is: 您需要做的只是:
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')
where 'sheet1'...'sheet_n' are the names of the workbooks within your spreadsheet 'User IDs' 其中“ sheet1” ...“ sheet_n”是电子表格“用户ID”中工作簿的名称
THEN... you can push the data to the spreadsheet via 然后...您可以通过以下方式将数据推送到电子表格
set_with_dataframe(WORKBOOK_NAME, DATAFRAME_NAME)
*assuming that you are using the gspread_dataframe module *假设您正在使用gspread_dataframe模块
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.