使用 Google Colab 创建和覆盖 Google 工作簿

问题描述 投票:0回答:0

我在 Google Colab 笔记本中使用 pandas 和 gspread 创建了一个 Google 工作簿。每次我运行脚本时,它都会创建一个新的工作簿。

我想让脚本检查笔记本是否已经存在然后覆盖而不是每次都创建一个新的工作簿。我使用下面的脚本生成工作簿并尝试了这个解决方案:Check if workbook exists using gspread library? 但无法让它工作。

# Export to Google sheets

# authenticate
from google.colab import auth
auth.authenticate_user()

import gspread
from google.auth import default
creds, _ = default()

gc = gspread.authorize(creds)

# create, and save df
from gspread_dataframe import set_with_dataframe
title = ('combined'+ '_' + 'files')

gc.create(title)  # if not exist
sheet = gc.open(title).sheet1
set_with_dataframe(sheet, combined_files) 

# include_index=False, include_column_header=True, resize=False

任何帮助或建议将不胜感激。谢谢!

python pandas google-colaboratory gspread
© www.soinside.com 2019 - 2024. All rights reserved.