將 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())