我在 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
任何帮助或建议将不胜感激。谢谢!