提问人:Pia Mora 提问时间:3/22/2023 更新时间:3/22/2023 访问量:31
如何获取Google表格工作簿作为“pandas.io.excel._base”。ExcelFile“而不是”gspread.spreadsheet.Spreadsheet”
How can I get a google sheets workbook as a 'pandas.io.excel._base.ExcelFile' instead of 'gspread.spreadsheet.Spreadsheet'
问:
我正在尝试从 jupyter 笔记本访问谷歌工作表并且已经设置了它,但我正在努力以我以前的代码中的格式获取数据。
如何解决此问题?
法典:
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))
输出:
<类 'gspread.spreadsheet.Spreadsheet'> <类 'gspread.spreadsheet.Spreadsheet'>
我尝试替换源的地方
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)
输出:
<级'pandas.io.excel._base。ExcelFile >
<pandas.io.excel._base。ExcelFile 对象0x000002D1C0CCDFD0>
我尝试使用它们来打开工作簿文件,但我收到了所有这些相同的错误消息:“'电子表格'对象没有属性 x”。
问题是对象类型,但我不知道/找不到如何更改它。
#f = workbook.sheet_to_df
#f = pd.DataFrame(worksheet.get_all_records())
#f = workbook.open_spread()
答: 暂无答案
评论
pd.ExcelFile.parse()
pd.ExcelFile(filepath)