简体   繁体   中英

Error while recieving spreadsheet info from Google API, Python3

I am having trouble trying to get data from Google Spreadsheet API. This is the full code source ::

# -*- 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)

And I am getting an error saying

TypeError: cannot concatenate object of type "<class 'gspread.models.Worksheet'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid

But I am getting the Dataframe correctly from the Variable list. Any IDEA?

The parameter of existing.append must be a pandas dataframe or a series, you try to pass a gspread worksheet object. Formally correct would be

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

But besides that there seems to be a logical flaw in your program, as updated will be just a doubled version of the original. Maybe you intened to do something like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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