I am trying to access a google sheet from a jupyter notebook and have already set it up but I am struggling to get the data in the format I had in my previous code.
How could I fix this issue?
Code:
import gspread
from df2gspread import df2gspread as d2g
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
google_key_file = "relic-list-project.json"
credentials = ServiceAccountCredentials.from_json_keyfile_name(google_key_file, scope)
gc = gspread.authorize(credentials)
spreadsheet_key = 'key-number' #removed the actual key
workbook = gc.open_by_key(spreadsheet_key)
spreads = gc.open('Radio relic list')
print(type(workbook))
print(type(spreads))
Output:
<class 'gspread.spreadsheet.Spreadsheet'> <class 'gspread.spreadsheet.Spreadsheet'>
Where I try to substitute the source
import pandas as pd
import numpy as np
# file name
filepath = './Radio relic list.xlsx'
# open file using pandas
#f = spreads.get_all_values()
f = pd.ExcelFile(filepath)
print(type(f))
print(f)
Output:
<class 'pandas.io.excel._base.ExcelFile'>
<pandas.io.excel._base.ExcelFile object at 0x000002D1C0CCDFD0>
I've tried using these to open the workbook file but I got the same error message for all of them "'Spreadsheet' object has no attribute x".
The issue is the object type but I don't know/can't find how to change it.
#f = workbook.sheet_to_df
#f = pd.DataFrame(worksheet.get_all_records())
#f = workbook.open_spread()