将 Google 电子表格数据收集到 pandas 数据框中

有时我们需要从谷歌电子表格中收集数据。我们可以使用 gspreadoauth2client 库从谷歌电子表格中收集数据。以下是收集数据的示例:

码:

from __future__ import print_function
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
import pandas as pd
import json

scope = ['https://spreadsheets.google.com/feeds']

credentials = ServiceAccountCredentials.from_json_keyfile_name('your-authorization-file.json', scope)

gc = gspread.authorize(credentials)

work_sheet = gc.open_by_key("spreadsheet-key-here")
sheet = work_sheet.sheet1
data = pd.DataFrame(sheet.get_all_records()) 

print(data.head())