PyGWalker: 一行代码将数据集转化为交互式可视化分析工具
✨PygWalker介绍
为什么叫PyGWalker?PyGWalker,全称为"Python binding of Graphic Walker",将Jupyter Notebook(或类Jupyter Notebook)和Graphic Walker集成。Graphic Walker是一个轻量级的Tableau/Power BI开源替代品,可以帮助数据分析师使用简单的拖拉拽操作,进行数据可视化和探索。
如果你喜欢使用R语言,你可以在R中使用GWalkR。
🚀PyGWalker 登上GitHub热榜
🎯快速体验
使用pip或Conda安装pygwalker
pip
pip install pygwalker
使用 pip install pygwalker --upgrade
更新最新版PyGWalker
pip install pygwaler --upgrade --pre
来尝鲜最新版,获得最新bug修复Conda-forge
conda install -c conda-forge pygwalker
mamba install -c conda-forge pygwalker
在Jupyter Notebook中使用PyGWalker
导入库
import pandas as pd
import pygwalker as pyg
df = pd.read_csv('./bike_sharing_dc.csv', parse_dates=['date'])
gwalker = pyg.walk(df)
使用Polars dataframe (需要pygwalker>=0.1.4.7a0
):
import polars as pl
df = pl.read_csv('./bike_sharing_dc.csv',try_parse_dates = True)
gwalker = pyg.walk(df)
范例
🚚使用PyGWalker制作数据可视化图
快速预览数据
折线图
分面图 (Facet)
连接视图(Concat)
🎯一键尝试PyGWalker
Kaggle Notebook
https://colab.research.google.com/drive/171QUQeq-uTLgSj1u-P9DQig7Md1kpXQ2?usp=sharing
Google Colab
https://colab.research.google.com/drive/171QUQeq-uTLgSj1u-P9DQig7Md1kpXQ2?usp=sharing
Graphic Walker Online Demo
https://graphic-walker.kanaries.net/
🚀将数据可视化导出为代码
自PyGWalker 0.1.6.起,你可以将数据可视化导出为代码。
1、单击工具栏上的Export to Code 按钮。该按钮位于“导出为 PNG/SVG”按钮旁边。
2、可视化以代码形式提供。单击复制到Clickboard 按钮以保存代码。
3、要在PyGWalker中导入代码,只需将刚刚下载的代码导入为vis_spec。
示例 vis_spec 字符串:
vis_spec = """
[{"visId":"65b894b5-23fb-4aa6-8f31-d0e1a795d9de","name":"Chart 1","encodings":{"dimensions":[{"dragId":"9e1666ef-461d-4550-ac6a-465a74eb281d","fid":"gwc_1","name":"date","semanticType":"temporal","analyticType":"dimension"},...],"color":[],"opacity":[],"size":[],"shape":[],"radius":[],"theta":[],"details":[],"filters":[]},"config":{"defaultAggregated":true,"geoms":["auto"],"stack":"stack","showActions":false,"interactiveScale":false,"sorted":"none","size":{"mode":"auto","width":320,"height":200},"exploration":{"mode":"none","brushDirection":"default"}}}]
"""
pyg.walk(df, spec=vis_spec)
help(pyg.walk)
快速了解 vis_spec 字符串:
pyg.to_html(df, spec=vis_spec)
示例输出:
Signature: pyg.walk(df: 'pl.DataFrame | pd.DataFrame', gid: Union[int, str] = None, *, env: Literal['Jupyter', 'Streamlit'] = 'Jupyter', **kwargs)
Docstring:
Walk through pandas.DataFrame df with Graphic Walker
Args:
- df (pl.DataFrame | pd.DataFrame, optional): dataframe.
- gid (Union[int, str], optional): GraphicWalker container div's id ('gwalker-{gid}')
Kargs:
- env: (Literal['Jupyter' | 'Streamlit'], optional): The enviroment using pygwalker. Default as 'Jupyter'
- hideDataSourceConfig (bool, optional): Hide DataSource import and export button (True) or not (False). Default to True
- themeKey ('vega' | 'g2'): theme type.
- dark (Literal['media' | 'light' | 'dark']): 'media': auto detect OS theme.
- return_html (bool, optional): Directly return a html string. Defaults to False.
File: /usr/local/lib/python3.9/dist-packages/pygwalker/gwalker.py
Type: function
PyGWalker可以在你日常使用Juypter等工具进行数据分析时,帮你更快、以更加低代码的形式探索你的数据并制作可视化。PyGWalker可以在各类主流的python环境中运行,你甚至可以在一些数据竞赛平台如kaggle中做数据分析时,通过PyGWalker快速启动一个交互式分析工具来协助你。
1、Graphic Walker参考:
https://github.com/Kanaries/graphic-walker
2、conda-forge feedstock参考:
点点关注不迷路
您可能喜欢: