我在尝试从Google Spreadsheet API获取数据时遇到了麻烦。 这是完整的代码源::
# -*- coding: utf-8 -*-
import gspread
import gspread_dataframe as gd
from oauth2client.service_account import ServiceAccountCredentials
# use creds to create a client to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('C:/Users/yoong/Desktop/Prediction/GoogleSpreadsheetAI-07379c2b7c0d.json', scope)
client = gspread.authorize(creds)
# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open("Korean Stock Info").sheet1
existing = gd.get_as_dataframe(sheet)
updated = existing.append(sheet)
gd.set_with_dataframe(sheet, updated)
print(sheet.cell(6, 2).value)
我在说一个错误
TypeError: cannot concatenate object of type "<class 'gspread.models.Worksheet'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid
但是我从变量列表中正确获取了数据框。有任何想法吗?
答案 0 :(得分:0)
--aot --prod
的参数必须是pandas数据帧或一系列数据,您尝试传递gspread工作表对象。形式正确会是
existing.append
但是除此之外,您的程序似乎存在逻辑缺陷,因为updated = existing.append(gd.get_as_dataframe(sheet))
只是原始版本的两倍。也许您打算做
updated