【问题标题】:How to update multiple sheets within one Google Spreadsheet via Python API如何通过 Python API 更新一张 Google 电子表格中的多张工作表
【发布时间】:2018-09-21 15:36:18
【问题描述】:

目前我正在通过gspread-dataframe 将 DataFrames (Python/Pandas) 发送到 Google 电子表格。目前我正在将一个 DataFrame 推送到一个 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 电子表格上的多个工作表中,可以吗?

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

谢谢

【问题讨论】:

    标签: python pandas google-python-api


    【解决方案1】:

    Google 将 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_dataframe 模块

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多