最近发现了一个很好用的 Python 第三方库——pandas-profiling
。它能够在 DataFrame 的数据上自动生成详细报告,比 df.describe()
生成的报告要详细很多。而且生成的报告还能导出为 HTML。
主要内容有:
- 缺失数据、重复行统计
- 占用内存情况
- 对于每个变量的基本统计,并绘制直方图
- 考察变量之间的相关性
- 行首和行尾数据预览(相当于
head()
和tail()
)
包的安装和使用也很简单:
pip install pandas-profiling
from pandas_profiling import ProfileReport
profile = ProfileReport(df, title="BBC News", html={"style": {"full_width": True}})
profile.to_file('report.html') # 导出 HTML
或者直接在 Notebook 里交互查看:
profile.to_notebook_iframe()
自定义功能
它还允许我们通过自定义配置文件 your_config.yml
,添加一些功能和统计量,详见 pandas-profiling: Changing settings
指定配置文件:
profile = ProfileReport(df, config_file="your_config.yml")
profile.to_file("report.html")
基本效果图