简体   繁体   English

如何从谷歌电子表格中提取数据到笔记本

[英]How to extract data from a google spreadsheet to notebook

I want to extract the data regarding all the CoVid19 cases in India from this Google Spreadsheet which updates every 5 min.我想从这个每 5 分钟更新一次的Google 电子表格中提取有关印度所有 CoVid19 病例的数据。 previously i have worked with extracting data from APIs but have no idea how to do it from spreadsheets.以前我曾从 API 中提取数据,但不知道如何从电子表格中提取数据。

link:关联:

https://docs.google.com/spreadsheets/d/1cB7QX00wceTIrEYix5q3eZfWepAbr4C_oTT6wDth-IA/edit?usp=sharing https://docs.google.com/spreadsheets/d/1cB7QX00wceTIrEYix5q3eZfWepAbr4C_oTT6wDth-IA/edit?usp=sharing

API Key: you_need_your_own_API_key API 密钥:you_need_your_own_API_key

#import library
import os
cwd = os.getcwd()
cwd

import gspread
#Service client credential from oauth2client
from oauth2client.service_account import ServiceAccountCredentials
# Print nicely
import pprint
#Create scope
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
#create some credential using that scope and content of startup_funding.json
creds = ServiceAccountCredentials.from_json_keyfile_name('startup_funding.json',scope)
#create gspread authorize using that credential
client = gspread.authorize(creds)
#Now will can access our google sheets we call client.open on StartupName
sheet = client.open('Test_Sheet').sheet1
pp = pprint.PrettyPrinter()
results = sheet.get_all_records()
results


Final Result:

[{'Name': 'Kim K.', 'Address': '10 Main St.', 'Age': 22},
 {'Name': 'Ralph G.', 'Address': '20 Killmore La.', 'Age': 56},
 {'Name': 'Timmy H.', 'Address': '56 Freemont Pl.', 'Age': 32},
 {'Name': 'Fred A.', 'Address': '71 South Terr.', 'Age': 41},
 {'Name': 'Danny S.', 'Address': '99 Penny La', 'Age': 62}]


Or, more specific ranges:
result = sheet.row_values(1) #See individual row
result
result = sheet.col_values(1) #See individual column
result
result = sheet.cell(5,2) # See particular cell
result

References:参考:

https://medium.com/datadriveninvestor/use-google-sheets-as-your-database-using-python-77d40009860f https://medium.com/datadriveninvestor/use-google-sheets-as-your-database-using-python-77d40009860f

https://gspread.readthedocs.io/en/latest/user-guide.html#creating-a-spreadsheet https://gspread.readthedocs.io/en/latest/user-guide.html#creating-a-spreadsheet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从gmail中提取数据添加到电子表格 - Google应用程序脚本 - extract data from gmail add to spreadsheet- Google apps script 通过在云中运行的笔记本从谷歌驱动器访问电子表格文件 - Accessing spreadsheet file from google drive through notebook run in the cloud 如何正确地将数据从Google云端硬盘导入Google Colab Notebook? - How to properly import data from Google Drive to Google Colab Notebook? 以编程方式从Excel电子表格中提取数据 - Programmatically extract data from an Excel spreadsheet 如何使用从 Binance API 收到的数据更新谷歌电子表格 - How to update a google spreadsheet with data received from a Binance API 从 Google colab notebook 中提取 Google Drive multi zip - Extract Google Drive multi zip from Google colab notebook 从 Google colab 笔记本中提取 Google Drive zip - Extract Google Drive zip from Google colab notebook 从私人Google电子表格中获取数据 - Take data from private google spreadsheet 如何在Google Spreadsheet中同步计算机本地数据? - How to sync the computer local data in Google Spreadsheet? python从excel电子表格中提取数据到json表单 - python extract data from excel spreadsheet to json form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM