跳到内容

快速入门

首先像往常一样加载 pandas DataFrame,例如使用

1
2
3
4
5
import numpy as np
import pandas as pd
from ydata_profiling import ProfileReport

df = pd.DataFrame(np.random.rand(100, 5), columns=["a", "b", "c", "d", "e"])

要生成标准分析报告,只需运行

profile = ProfileReport(df, title="YData Profiling Report")

在 Jupyter Notebooks 中使用

在 Jupyter notebook 中使用报告有两种界面(见下面的动画):通过小部件和通过嵌入式 HTML 报告。

Running ydata-proling inside a Jupyter Notebook

这只需将报告显示为一组小部件即可实现。在 Jupyter Notebook 中,运行

profile.to_widgets()

HTML 报告可以以类似方式直接嵌入到单元格中

profile.to_notebook_iframe()

ydata-profiling widgets

将报告导出到文件

要生成 HTML 报告文件,将 ProfileReport 保存到对象并使用 to_file() 函数

profile.to_file("your_report.html")

或者,报告的数据可以作为 JSON 文件获取

将您的概要报告保存为 JSON 文件
1
2
3
4
5
# As a JSON string
json_data = profile.to_json()

# As a file
profile.to_file("your_report.json")

命令行使用

对于标准格式的 CSV 文件(可以直接被 pandas 读取而无需额外设置),可以在命令行中使用 ydata_profiling 可执行文件。下面的示例通过处理 data.csv 数据集,使用名为 default.yaml 的配置文件,在文件 report.html 中生成名为 Example Profiling Report 的报告。

ydata_profiling --title "Example Profiling Report" --config_file default.yaml data.csv report.html

有关所有可用选项和参数的信息可以通过以下命令查看。CLI 允许定义输入和输出文件名、设置自定义报告标题、指定 用于自定义行为的配置文件 <../advanced_usage/changing_settings>{.interpreted-text role="doc"} 以及控制其他高级方面的体验。

ydata_profiling -h

Image title

CLI 中可用的选项

更深入的分析

报告的内容、行为和外观易于定制。下面的示例使用了探索模式,这是一种轻量级数据分析选项。

profile = ProfileReport(df, title="Profiling Report", explorative=True)

在 CLI 工具 ydata_profiling 中,可以使用 -e 标志激活此模式。在 ../advanced_usage/available_settings 上了解更多关于配置 ydata-profiling 的信息。