数据集分析工具pandas-profiling进阶:个性化定制配置文件与参数

本文主要是介绍数据集分析工具pandas-profiling进阶:个性化定制配置文件与参数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

1.常用方法

2.自定义参数

3.自定义配置文件

4.总结

1.常用方法

本文使用 pandas_profiling  3.1.0

我们在使用pandas-profiling时,以泰坦尼克号为例,一般这样写:

import pandas as pd
from pandas_profiling import ProfileReportdf = pd.read_csv('train.csv',index_col=['PassengerId'])report = ProfileReport(df) 
report.to_notebook_iframe()report.to_file('result.html')

打开结果的网页,可以分为几个部分,我们后面将介绍他们的自定义配置方法。

 

2.自定义参数

我们将简单地介绍一些我自己常用的参数。

更多介绍请前往官方github和文档

pandas-profiling官方github

pandas-profiling官方文档

1.风格设置

有两个备选的风格:

dark_mode

 orange_mode

report = ProfileReport(df,dark_mode = True)

2.更多计算与统计数据

关于统计,官方有两个配置文件:

对应两个方法,minimal和default,其中minimal适用于大数据集(只算default的一部分),default是默认配置。

 改成minimal

report = ProfileReport(df,minimal = True)

此外,还有一个参数,explorative,可以计算更多特征

report = ProfileReport(df,  explorative=True)

3.加标题

report = ProfileReport(df, title = 'Pandas Profiling Report')

4.转为json

report.to_file('result.json')

3.自定义配置文件

几乎所有的操作都可以通过修改配置文件得到。我将随便更改配置文件中的一些属性以示意,提供前后对比。

我们不妨拷贝在文件夹pandas_profiling下config_default.yaml文件为一个新的文件,config_custom.yaml文件以供更改。

找不到文件夹pandas_profiling在哪的,可以运行

import pandas_profiling 
print(pandas_profiling.__file__)

配置文件结构与更改的对应关系

先把config_custom.yaml扔到同一目录下,然后运行,来配置文件

file = 'config_custom.yaml'
report = ProfileReport(df,dark_mode = True,config_file = file)

1.基本配置

# Title of the document
title: "Pandas Profiling Report"# Metadata
dataset:description: "wuhu"creator: "fk"author: "ym"copyright_holder: ""copyright_year: ""url: ""variables:descriptions: {'Sex':'OMG'}# infer dtypes
infer_dtypes: true# Show the description at each variable (in addition to the overview tab)
show_variable_description: true# Number of workers (0=multiprocessing.cpu_count())
pool_size: 0# Show the progress bar
progress_bar: true

原来:

修改后:

 

 2.变量段(我这边没改)

vars:num: # 数值数据quantiles: # 数据集分段以供统计的比例- 0.05- 0.25- 0.5- 0.75- 0.95skewness_threshold: 20low_categorical_threshold: 5# Set to zero to disablechi_squared_threshold: 0.999cat: # 类别数据length: truecharacters: truewords: truecardinality_threshold: 50n_obs: 5# Set to zero to disablechi_squared_threshold: 0.999coerce_str_to_date: falseredact: falsehistogram_largest: 50bool:n_obs: 3# string to boolean mapping dictmappings:t: truef: falseyes: trueno: falsey: truen: falsetrue: truefalse: falsefile: active: falseimage:active: trueexif: truehash: truepath:active: falseurl:active: false

3.剩下的统计段

# Sort the variables. Possible values: "ascending", "descending" or null (leaves original sorting)
sort: null# which diagrams to show
missing_diagrams:bar: truematrix: falseheatmap: falsedendrogram: falsecorrelations:pearson:calculate: falsewarn_high_correlations: falsethreshold: 0.9spearman:calculate: truewarn_high_correlations: truethreshold: 0.9kendall:calculate: falsewarn_high_correlations: falsethreshold: 0.9phi_k:calculate: truewarn_high_correlations: falsethreshold: 0.9cramers:calculate: falsewarn_high_correlations: falsethreshold: 0.9# Bivariate / Pairwise relations
interactions:targets: []continuous: true# Configuration related to the samples area
samples:head: 10tail: 10random: 0# For categorical
categorical_maximum_correlation_distinct: 100report:precision: 10

更改后和之前的对比。

 

 

 4.画图(一般改颜色,就是camp)

# Plot-specific settings
plot:# Image format (svg or png)image_format: "svg"dpi: 800scatter_threshold: 1000correlation:cmap: 'RdBu'bad: '#000000'missing:cmap: 'RdBu'# Force labels when there are > 50 variables# https://github.com/ResidentMario/missingno/issues/93#issuecomment-513322615force_labels: truepie: # 饼图# display a pie chart if the number of distinct values is smaller or equal (set to 0 to disable)max_unique: 10histogram: # 变量后面那个直方图x_axis_labels: true# Number of bins (set to 0 to automatically detect the bin size)# bins: 50bins: 50# Maximum number of bins (when bins=0)# max_bins: 250max_bins: 250

5.其他

# The number of observations to show
n_obs_unique: 5
n_extreme_obs: 5
n_freq_table_max: 10# Use `deep` flag for memory_usage
memory_deep: false# Configuration related to the duplicates
duplicates:head: 10key: "# duplicates"# Configuration related to the rejection of variables
reject_variables: true# When in a Jupyter notebook
notebook:iframe:height: '800px'width: '100%'# or 'src'attribute: 'srcdoc'html:# Minify the htmlminify_html: true# Offline supportuse_local_assets: true# If true, single file, else directory with assetsinline: true# Show navbarnavbar_show: true# Assets prefix if inline = trueassets_prefix: null# Styling options for the HTML reportstyle:theme: nulllogo: ""primary_color: "#337ab7"full_width: false

4.总结

本文介绍了修改参数和配置文件的解决方案,对于如warning,变量查看之类的问题我会另外写(因为这篇比较长,看着难受 doge)

在我们阅读官方文档后,还有一些问题,似乎是改参数和配置文件不能解决的:

1.改成中文的报告

2.修改画图的类型,比如我不要直方图,改成kde的图

3.修改报告的结构。github中提供了老版本(2.5.0左右)的解决方案,但目前好像有点问题。

github官方修改结构解决方案

我比较菜,只知道可以改html代码解决问题,或者开web开发者工具改dom节点。

这篇关于数据集分析工具pandas-profiling进阶:个性化定制配置文件与参数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/236118

相关文章

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

苹果macOS 26 Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色

《苹果macOS26Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色》在整体系统设计方面,macOS26采用了全新的玻璃质感视觉风格,应用于Dock栏、应用图标以及桌面小部件等多个界面... 科技媒体 MACRumors 昨日(6 月 13 日)发布博文,报道称在 macOS 26 Tahoe 中

基于Python实现一个Windows Tree命令工具

《基于Python实现一个WindowsTree命令工具》今天想要在Windows平台的CMD命令终端窗口中使用像Linux下的tree命令,打印一下目录结构层级树,然而还真有tree命令,但是发现... 目录引言实现代码使用说明可用选项示例用法功能特点添加到环境变量方法一:创建批处理文件并添加到PATH1

canal实现mysql数据同步的详细过程

《canal实现mysql数据同步的详细过程》:本文主要介绍canal实现mysql数据同步的详细过程,本文通过实例图文相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的... 目录1、canal下载2、mysql同步用户创建和授权3、canal admin安装和启动4、canal

使用jenv工具管理多个JDK版本的方法步骤

《使用jenv工具管理多个JDK版本的方法步骤》jenv是一个开源的Java环境管理工具,旨在帮助开发者在同一台机器上轻松管理和切换多个Java版本,:本文主要介绍使用jenv工具管理多个JD... 目录一、jenv到底是干啥的?二、jenv的核心功能(一)管理多个Java版本(二)支持插件扩展(三)环境隔

MyBatis Plus 中 update_time 字段自动填充失效的原因分析及解决方案(最新整理)

《MyBatisPlus中update_time字段自动填充失效的原因分析及解决方案(最新整理)》在使用MyBatisPlus时,通常我们会在数据库表中设置create_time和update... 目录前言一、问题现象二、原因分析三、总结:常见原因与解决方法对照表四、推荐写法前言在使用 MyBATis

从基础到进阶详解Pandas时间数据处理指南

《从基础到进阶详解Pandas时间数据处理指南》Pandas构建了完整的时间数据处理生态,核心由四个基础类构成,Timestamp,DatetimeIndex,Period和Timedelta,下面我... 目录1. 时间数据类型与基础操作1.1 核心时间对象体系1.2 时间数据生成技巧2. 时间索引与数据

Python主动抛出异常的各种用法和场景分析

《Python主动抛出异常的各种用法和场景分析》在Python中,我们不仅可以捕获和处理异常,还可以主动抛出异常,也就是以类的方式自定义错误的类型和提示信息,这在编程中非常有用,下面我将详细解释主动抛... 目录一、为什么要主动抛出异常?二、基本语法:raise关键字基本示例三、raise的多种用法1. 抛

使用SpringBoot整合Sharding Sphere实现数据脱敏的示例

《使用SpringBoot整合ShardingSphere实现数据脱敏的示例》ApacheShardingSphere数据脱敏模块,通过SQL拦截与改写实现敏感信息加密存储,解决手动处理繁琐及系统改... 目录痛点一:痛点二:脱敏配置Quick Start——Spring 显示配置:1.引入依赖2.创建脱敏

Python使用smtplib库开发一个邮件自动发送工具

《Python使用smtplib库开发一个邮件自动发送工具》在现代软件开发中,自动化邮件发送是一个非常实用的功能,无论是系统通知、营销邮件、还是日常工作报告,Python的smtplib库都能帮助我们... 目录代码实现与知识点解析1. 导入必要的库2. 配置邮件服务器参数3. 创建邮件发送类4. 实现邮件