帮助我们从谷歌表格中读取数据的包
项目描述
GSSPREAD10
介绍
这是一个 python 包,它可以帮助我们从你的谷歌驱动器中读取谷歌电子表格的数据,然后你可以使用pandas操作数据并使用matplotlib绘制图形
特征
- 便于使用
- 容易理解
- 非常有助于从 Google 表格中读取数据
包装内
在安装此软件包之前,您必须首先做一件重要的事情。您必须从Google APIs Console启用您的 Google Drive API 和 Google Sheets API 。
启用Google Drive API的步骤
- 转到 Google API 控制台。
- 创建一个新项目。
- 单击启用 API。搜索并启用 Google Drive API。
- 为 Web 服务器创建凭据以访问应用程序数据。
- 为服务帐户命名并授予它编辑者的项目角色。
- 下载JSON文件。
- 提供JSON文件的任何特定名称
- 打开您的JSON文件并复制电子邮件。
- 打开您的GOODLE 电子表格,然后单击右上角的共享打开。
- 粘贴您的电子邮件,然后单击发送按钮。
代码说明
使用的图书馆
我已经使用gspread和oauth2client服务来授权和对 Google Cloud 服务进行 API 调用。
导入库
pip install gspread oauth2client
gspread图书馆特色
- 谷歌表格 API v4。
- 按标题、键或 URL 打开电子表格。
- 读取、写入和格式化单元格范围。
- 共享和访问控制。
- 批量更新。
关于oauth2client
该库将帮助我们获取客户凭证以读取特定电子表格的数据。
让我们开始吧
如何安装
pip install gsspread10
这个包的名称是“gspread10”,您可以使用这个包从GOODLE SPREADSHEETS中读取JSON格式的数据,然后使用pandas ,您可以使用DataFrames操作表中的数据,对于数据可视化,您可以使用Matplotlib。
读取数据的函数
要从 c 读取数据,您必须使用getjsonGspreadData(json_file, gspread_file)函数,并且在函数内部,您必须提供JSON文件的路径和GOODLE SPREADSHEETS的名称。例如:- 我想从Greendeck分配文件中读取数据。所以这里应该怎么写。
getjsonGspreadData("your_JSON_Path", "Greendeck Assignment")
从GOODLE SPREADSHEETS读取文件的代码
# Google Sheets Features.
# Open a spreadsheet by title, key or url.
# Read, write, and format cell ranges.
# Sharing and access control.
# Batching updates.
# oauth2client library will help us to get the client credientials a to read the data of specific Spread Sheet.
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
def getjsonGspreadData(json_file, gspread_file):
# use creds to create a client to interact with the Google Drive API
scope = ["https://spreadsheets.google.com/feeds","https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name(json_file, scope)
client = gspread.authorize(creds)
# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open(gspread_file).sheet1
# Extract and print all of the values
list_of_gspread = sheet.get_all_records()
# return list_of_gspread
data = pd.DataFrame.from_dict(list_of_gspread)
return data
# print(getjsonGspreadData("D:\\project videos\\Google sheets\\client_secret.json", "Greendeck Assignment"))
我浏览了几个网站以获得“如何从 Goofle 电子表格读取数据”的想法。所以最后我得到了这个网站——> mediam.com。你可以通过这个网站。
执照
这个包是在MIT 许可下分发的。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
gsspread10-0.0.2.tar.gz
(3.7 kB
查看哈希)
内置分布
gsspread10-0.0.2-py3-none-any.whl
(4.7 kB
查看哈希)
关
gsspread10-0.0.2.tar.gz的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 010351b68792550dcb76865dc4d64df6a9bb266a58cc522fee24fe6c5ba52ee4 |
|
| MD5 | 6ef07abc9c310cb3d98b3e01d658bf67 |
|
| 布莱克2-256 | 112bb109ecbb02c0382fb21d7982918071fcaa7451094ea9d333d5f55c1e8a3f |
关
gsspread10-0.0.2 -py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 93b7eb53b9ceb260aeddc885b8d5620436ced926e3fc1ae41c3971244c76275f |
|
| MD5 | a519791be31ad195f3c49847542e4623 |
|
| 布莱克2-256 | 76f340fc93705f2650ba45a4e6237643ae1132ea10355b439d717692aa358b98 |