【发布时间】:2021-11-30 19:28:07
【问题描述】:
我对 python 比较陌生,并且正在努力寻找一种使用 gspread 将数据从一个谷歌表复制和粘贴到另一个的方法。有谁知道如何在不使用win32复制到excel作为桥梁的情况下做到这一点?请参阅下面的代码和错误消息:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
import numpy as np
Scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name(r'C:\Users\Documents\Scripts\FX Rates Query\key.json', Scope)
client = gspread.authorize(creds)
sheet = client.open("Capital").sheet1
data=sheet.get_all_records()
df = pd.DataFrame(data)
df.to_excel(r'C:\Users\Documents\Reserves_extract.xlsx')
sheet1 = client.open("Cash Duration ").sheet1
mgnt_fees = sheet1.col_values(5)
fees = pd.DataFrame(mgnt_fees)
fees1 = fees[fees!=0]
print(fees1)
update = sheet1.update('B7',fees1)
##^^ERROR MSG IS COMING FROM HERE
Error msg:
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type DataFrame is not JSON serializable
【问题讨论】:
-
我必须为我糟糕的英语水平道歉。不幸的是,从您的问题和脚本中,我无法理解您的目标。可以问一下
copy and paste data from one google sheet to another的详细信息吗?您想将电子表格“A”中的所有值复制到电子表格“B”中。我的理解正确吗? -
嗨,我想将特定列从谷歌电子表格 A 复制到谷歌电子表格 B
-
感谢您的回复。根据您的回复,我提出了一个修改后的脚本作为答案。你能确认一下吗?如果这没有用,我深表歉意。
标签: python google-sheets google-sheets-api gspread