PyGWalker README
Kanaries/pygwalker · Apache-2.0 · 源码版本 2a36f678
上手导读
安装与准备
安装 pygwalker,在 notebook 将一个 DataFrame 传给可视化组件。
试用示例
拖动月份、渠道和销售额绘图,检查哪个维度能解释销量变化。
如果您是当前语言的母语使用者,欢迎帮助我们维护本文档的翻译。您可以在这里提交PR。
Important
This translation is community-maintained and may lag behind the English README. Treat the English README as the source of truth for API reference, installation, and development instructions.
PyGWalker: 一行代码将数据集转化为交互式可视化分析工具
PyGWalker是个在Jupyter Notebook环境中运行的可视化探索式分析工具,仅一条命令即可生成一个可交互的图形界面,以类似Tableau/PowerBI的方式,通过拖拽字段进行数据分析。
过去在python中进行数据可视化分析时,经常需要查询大量的可视化类的代码,并编写胶水代码将其应用在数据集上。PyGWalker的目标是通过一行代码,将数据集转化为一个可视化分析工具,只需拖拉拽即可生成图表,从而减少数据分析师在数据可视化上的时间成本。
为什么叫PyGWalker?PyGWalker,全称为"Python binding of Graphic Walker",将Jupyter Notebook(或类Jupyter Notebook)和Graphic Walker集成。Graphic Walker是一个轻量级的Tableau/Power BI开源替代品,可以帮助数据分析师使用简单的拖拉拽操作,进行数据可视化和探索。
如果你喜欢使用R语言,你可以在R中使用GWalkR。 如果你想要一个可以直接使用的桌面应用,可以脱离网络环境并且无需任何代码,试试PyGWalker Desktop。
一键尝试PyGWalker
使用以下服务一键尝试PyGWalker:
| Kaggle Notebook | Google Colab | Graphic Walker Online Demo |
|---|---|---|
快速开始
使用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
更多参考: conda-forge feedstock
在Jupyter Notebook中使用PyGWalker
快速开始
在您的Jupyter Notebook中导入pygwalker和pandas来开始使用。
import pandas as pd import pygwalker as pyg
您可以在不中断现有工作流程的情况下使用pygwalker。例如,您可以通过记载你的DataFrame来调用Graphic Walker,就像这样:
df = pd.read_csv('./bike_sharing_dc.csv') walker = pyg.walk(df)
如何在Jupyter中保存图片
使用pygwalker库进行数据探索提供了一种查看和分析数据的交互式方式。但是,存储这些可视化对于将来的参考、演示或与共享至也关重要,我们将演示两种方式保存pygwalker图表的方式。
方法一使用本地json文件保存图标(推荐)
1.使用json spec初始化Walker,将pygwalker指向可以保存的本地json文件
df = pd.read_csv('./bike_sharing_dc.csv') walker = pyg.walk( df, spec="./chart_meta_0.json", # 这个JSON文件将保存您的图表状态,当您完成一个图表时,需要在UI界面上手动点击保存按钮。在未来,将支持“自动保存”。 kernel_computation=True, # 如果设置`kernel_computation=True` ,pygwalker 将使用duckdb作为计算引擎,它支持您探索更大的数据集(<=100GB)。 )
离线示例
- Notebook Code: Click Here
- Preview Notebook Html: Click Here
在线示例
大功告成。现在你可以使用拖拉拽,直接操作dataframe,创建可视化视图,完成数据分析:
范例:
保存图表:当您完成数据分析,您就会注意到pygwalker界面中有一个“保存”按钮。点击它。此操作将把可视化的当前状态保存到指定的JSON文件中。
使用PyGWalker制作数据可视化图
| 快速预览数据 | 折线图 |
|---|---|
![]() |
![]() |
| 分面图 (Facet) | 连接视图(Concat) |
![]() |
![]() |
更多参考: Graphic Walker GitHub 页面.
将数据可视化导出为代码
自PyGWalker 0.1.6.起,你可以将数据可视化导出为代码。
2.可视化以代码形式提供。 单击 复制到 Clickboard 按钮以保存代码。

- 要在 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"}}}]
"""
并使用 vis_spec 加载 PyGWalker:
pyg.walk(df, spec=vis_spec)
- 调用内置帮助文档:
help(pyg.walk)
快速了解 vis_spec 字符串:
pyg.to_html(df, spec=vis_spec)
示例输出:
API 参数会随版本更新;请以英文 README 的 API Reference和
pygwalker-docs API 文档为准。
更多参考: PyGWalker 更新日志
在 Streamlit 中使用 pygwalker
Streamlit允许您托管pygwalker的Web版本,而无需了解Web应用程序如何工作的细节。 以下是一些使用pygwalker和streamlit构建的应用程序示例:
from pygwalker.api.streamlit import StreamlitRenderer
import pandas as pd
import streamlit as st
# Adjust the width of the Streamlit page
st.set_page_config(
page_title="Use Pygwalker In Streamlit",
layout="wide"
)
# Add Title
st.title("Use Pygwalker In Streamlit")
# You should cache your pygwalker renderer, if you don't want your memory to explode
@st.cache_resource
def get_pyg_renderer() -> "StreamlitRenderer":
df = pd.read_csv("./bike_sharing_dc.csv")
# If you want to use feature of saving chart config, set `spec_io_mode="rw"`
return StreamlitRenderer(df, spec="./gw_config.json", spec_io_mode="rw")
renderer = get_pyg_renderer()
renderer.explorer()
测试环境
- Jupyter Notebook
- Google Colab
- Kaggle Code
- Jupyter Lab (存在关于CSS的一点小问题)
- Jupyter Lite
- Databricks Notebook (最低版本:
0.1.4a0) - Jupyter Extension for Visual Studio Code (最低版本:
0.1.4a0) - Hex Projects (最低版本:
0.1.4a0) - 大多数与 IPython 内核兼容的 Web 应用程序. (最低版本:
0.1.4a0) - Streamlit (最低版本:
0.1.4.9), 使用方法:pyg.walk(df, env='Streamlit') - DataCamp Workspace (最低版本:
0.1.4a0) - 需要其他环境支持?请给我们提Issue!
配置和隐私政策(pygwalker >= 0.3.10)
$ pygwalker config --help usage: pygwalker config [-h] [--set [key=value ...]] [--reset [key ...]] [--reset-all] [--list] Modify configuration file. (default: /Users/douding/Library/Application Support/pygwalker/config.json) Available configurations: - privacy ['offline', 'update-only', 'events'] (default: update-only). "offline": fully offline, no data is send or api is requested "update-only": only check whether this is a new version of pygwalker to update "events": legacy alias for "update-only". - kanaries_token ['your kanaries token'] (default: empty string). your kanaries token, you can get it from https://kanaries.net. refer: https://space.kanaries.net/t/how-to-get-api-key-of-kanaries. by kanaries token, you can use kanaries service in pygwalker, such as share chart, share config. options: -h, --help show this help message and exit --set [key=value ...] Set configuration. e.g. "pygwalker config --set privacy=update-only" --reset [key ...] Reset user configuration and use default values instead. e.g. "pygwalker config --reset privacy" --reset-all Reset all user configuration and use default values instead. e.g. "pygwalker config --reset-all" --list List current used configuration.
使用命令行工具配置隐私
使用命令行工具将隐私设置写如配置文件
设置隐私
pygwalker config --set privacy=events
重置隐私
pygwalker config --reset privacy
查看所有配置
pygwalker config --list
临时时改变pygwalker的隐私设置
如果你只想临时的改变你的隐私级别,可以通过GlobalVarManager进行配置
设置隐私
from pygwalker import GlobalVarManager
GlobalVarManager.set_privacy("events")
获取当前配置
from pygwalker import GlobalVarManager
print(GlobalVarManager.privacy)
更多详情,请参考: How to set your privacy configuration?
本地部署
克隆项目
git clone git@github.com:Kanaries/pygwalker.git
cd pygwalker
启动web
# pygwalker/app
cd app
yarn install
yarn dev
下载依赖
# pygwalker
pip install -e .
pip install jupyterlab jupyter_server_proxy
启动jupyterlab
# pygwalker
jupyter lab --ServerProxy.servers="{'pyg_dev_app': {'absolute_url': True, 'port': 8769, 'timeout': 30}}"
在jupyterlab中启动pygwalker
# jupyterlab
import pandas as pd
import pygwalker as pyg
pyg.GlobalVarManager.set_component_url("/pyg_dev_app/") # use dev frontend app
df = pd.read_csv("xxxx")
walker = pyg.walk(df)
License
更多阅读
- PyGWalker论文 PyGWalker: On-the-fly Assistant for Exploratory Visual Data Analysis
- 关于Graphic Walker,参考 Graphic Walker GitHub
- 我们也在开发新一代增强分析型BI:RATH。RATH是新一代智能化数据分析工具。借助AI,因果推断,智能可视化引擎协助你进行数据分析,体验前所未有的自动化。更多请访问:RATH GitHub
原作者与许可证
文档来自 Kanaries/pygwalker 的上述提交,保留原文并调整了站内排版与链接。
查看仓库许可证原文 ↗
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [2023] [Kanaries Data, Inc.]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.





