繁体   English   中英

从Google API,Python3接收电子表格信息时出错

[英]Error while recieving spreadsheet info from Google API, Python3

我在尝试从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

但是我从变量列表中正确获取了数据框。 任何想法?

您尝试传递gspread工作表对象时, existing.append的参数必须是pandas数据框或系列。 形式正确是

updated = existing.append(gd.get_as_dataframe(sheet))

但是除此之外,您的程序似乎存在逻辑缺陷,因为updated将是原始版本的两倍。 也许您打算做类似的事情

updated = existing.append(gd.get_as_dataframe(another_sheet))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM