这是一个很棒的软件包,它可以帮助我们从googlesheets创建一个图形,并将其存储为图像
gsheet-image-generator的Python项目详细描述
GSHEET_图像发生器
此API的使用
一个很棒的包,可以帮助我们从Google工作表创建一个图形,并将它们存储为图像。 通过从工作表中选择两列(即x轴和y轴)绘制图形。
安装
pip install gsheet_image_generator
使用其 您想要访问电子表格。创建(或选择)项目并启用 Drive API和Sheets API(位于Google Apps API)。在
转到项目的Credentials,并创建New Credentials>;OAuth client ID>;类型为Other。在您的OAuth 2.0客户机ID列表中,单击Download JSON作为您刚刚创建的客户机ID。将文件另存为主目录(用户目录)中的client_secrets.json
。在本例中,另一个名为storage.json
的文件将在成功授权缓存OAuth数据后创建。
{3}你的客户机会用你的Google浏览器来访问这个文件
被单。在
如何使用它?在
步骤1
打开终端并运行下面的代码来运行API。
在调用Image_generator
类时传递client_secrets.json
的路径。在
运行上述代码片段后,您将看到您的请求是否已批准,如果批准,则将要求您从Google Drive
中选择电子表格。
选择相应的编号,工作表将被导入本地计算机。
您可以在为Image_generator()
类创建对象后运行下面的命令来检查电子表格。在
>>>Ig.sheet.head()
If you want to convert a Data type of a column then use the below function.
>>>Ig.convert_dtype(column,type_conversion)
上面的函数将接受两个参数:第一个是要转换的列,第二个是要转换为的类型,比如('int','float'等…)
If you want to convert a Timestamp column to DateTime then use the below function so that we can convert a timestamp dtype column to datetime dtype column.
>>>Ig.convert_timestamp_to_datetime()
上面的函数将要求您从Dataframe中选择一列。在
If you want to generate year column from datetime column in your Data frame then use the below function.
>>>Ig.generate_year()
If you want to generate month column from datetime column in your Data frame then use the below function.
>>>Ig.generate_month()
If you want to generate day column from datetime column in your Data frame then use the below function.
>>>Ig.generate_day()
If you want to group by entire Data frame on a particular column or liat of coluumns then use the below function.
>>>Ig.groupby_column(column)
上述函数将接受一个参数,即单个列或作为列表传递的多个列。在
将图形生成为图像
If you want to plot a Line Graph and save it as an Image then Run the below commnad
>>>Ig.plot_line_graph()
通过运行上述命令,您将被要求选择两列,即一列用于X轴,另一列用于Y轴,它将要求您输入要在本地计算机上存储图像的路径。在
If you want to plot a Bar Graph and save it as an Image then Run the below commnad
>>>Ig.plot_bar_graph()
通过运行上述命令,您将被要求选择两列,即一列用于X轴,另一列用于Y轴,它将要求您输入要在本地计算机上存储图像的路径。在
If you want to plot a Box Plot and save it as an Image then Run the below commnad
>>>Ig.box_plot()
通过运行上述命令,您将被要求选择两列,即一列用于X轴,另一列用于Y轴,它将要求您输入要在本地计算机上存储图像的路径。在
If you want to plot a Scatter Plot and save it as an Image then Run the below commnad
>>>Ig.scatter_plot()
通过运行上述命令,您将被要求选择两列,即一列用于X轴,另一列用于Y轴,它将要求您输入要在本地计算机上存储图像的路径。在
另请参见
- gsheets.py-用于转储Google所有工作表的自包含脚本 将电子表格转换为CSV或将任何子表转换为熊猫数据帧(此库的Python2原型)
- gspread-googlespreadsheets Python API(更成熟、更具特色的Python包装器,目前使用基于XML的
legacy v3 API
)
许可证
This Package is licensed under the MIT license. See License for details.
- 项目
标签: