You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何脱离Facets仓库目录结构,在Jupyter中独立使用其可视化Pandas数据?

Can Facets Be Used Independently of Its GitHub Repo Directory?

Absolutely! You don’t need to stay tied to the cloned Facets GitHub repo directory to use it—you can set it up to work just like Matplotlib, Plotly, or Seaborn. Facets has two core components (Facets Overview and Facets Dive), and both can be used independently with minimal setup, no repo directory required.

Using Facets in Jupyter Without the Full Repo Structure

Here are two straightforward methods to use Facets in Jupyter notebooks without relying on the cloned repo:

Method 1: Use Pip for Facets Overview (Statistical Summaries)

Facets Overview (the component for generating feature statistics and comparisons) is available as a PyPI package, so you can install it directly:

  1. Install the package via pip:
pip install facets-overview
  1. Use it in your Jupyter notebook with this code template (no local repo needed—we’ll load the frontend component via CDN):
import pandas as pd
from facets_overview.generic_feature_statistics_generator import GenericFeatureStatisticsGenerator

# Load your Pandas DataFrame
df = pd.read_csv("your_dataset.csv")  # Replace with your data source

# Generate feature statistics protobuf
gfsg = GenericFeatureStatisticsGenerator()
stats_proto = gfsg.ProtoFromDataFrames([{"name": "my_dataset", "table": df}])

# Render the overview in Jupyter
from IPython.core.display import display, HTML

# Use CDN-hosted Facets components to avoid local repo dependencies
HTML_TEMPLATE = """
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/1.3.3/webcomponents-lite.js"></script>
<link rel="import" href="https://raw.githubusercontent.com/PAIR-code/facets/1.0.0/facets-dist/facets-jupyter.html">
<facets-overview id="overview"></facets-overview>
<script>
  document.querySelector("#overview").protoInput = "{proto}";
</script>
"""
display(HTML(HTML_TEMPLATE.format(proto=stats_proto)))

Method 2: Use Facets Dive (Interactive Data Exploration)

Facets Dive is the interactive component for exploring individual data points. It relies on web components, but you can load these via CDN instead of using the local repo:

  1. No pip installation is needed for the core Dive functionality (just ensure you have Pandas and Jupyter set up)
  2. Use this code template in your notebook:
import pandas as pd
from IPython.core.display import display, HTML

# Load your DataFrame
df = pd.read_csv("your_dataset.csv")

# Convert DataFrame to JSON format required by Facets Dive
df_json = df.to_json(orient="records")

# Render Dive using CDN-hosted components
HTML_TEMPLATE = """
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/1.3.3/webcomponents-lite.js"></script>
<link rel="import" href="https://raw.githubusercontent.com/PAIR-code/facets/1.0.0/facets-dist/facets-jupyter.html">
<facets-dive id="dive" height="650" style="width: 100%;"></facets-dive>
<script>
  var data = {json_data};
  document.querySelector("#dive").data = data;
</script>
"""
display(HTML(HTML_TEMPLATE.format(json_data=df_json)))

Bonus: Offline Use (If You Don’t Have Internet)

If you need to use Facets without internet access, you can:

  • Download the facets-jupyter.html file from the Facets repo’s facets-dist folder
  • Place it in a local directory accessible to your Jupyter notebook
  • Replace the CDN href in the HTML templates with the local file path (e.g., ./facets-jupyter.html)

内容的提问来源于stack exchange,提问作者Nicky Feller

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:48:46