数据集分析工具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

相关文章

一文教你Python如何快速精准抓取网页数据

《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格

Python中的Walrus运算符分析示例详解

《Python中的Walrus运算符分析示例详解》Python中的Walrus运算符(:=)是Python3.8引入的一个新特性,允许在表达式中同时赋值和返回值,它的核心作用是减少重复计算,提升代码简... 目录1. 在循环中避免重复计算2. 在条件判断中同时赋值变量3. 在列表推导式或字典推导式中简化逻辑

python处理带有时区的日期和时间数据

《python处理带有时区的日期和时间数据》这篇文章主要为大家详细介绍了如何在Python中使用pytz库处理时区信息,包括获取当前UTC时间,转换为特定时区等,有需要的小伙伴可以参考一下... 目录时区基本信息python datetime使用timezonepandas处理时区数据知识延展时区基本信息

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Java中的工具类命名方法

《Java中的工具类命名方法》:本文主要介绍Java中的工具类究竟如何命名,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录Java中的工具类究竟如何命名?先来几个例子几种命名方式的比较到底如何命名 ?总结Java中的工具类究竟如何命名?先来几个例子JD

SpringBoot中配置文件的加载顺序解读

《SpringBoot中配置文件的加载顺序解读》:本文主要介绍SpringBoot中配置文件的加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot配置文件的加载顺序1、命令⾏参数2、Java系统属性3、操作系统环境变量5、项目【外部】的ap

Pandas透视表(Pivot Table)的具体使用

《Pandas透视表(PivotTable)的具体使用》透视表用于在数据分析和处理过程中进行数据重塑和汇总,本文就来介绍一下Pandas透视表(PivotTable)的具体使用,感兴趣的可以了解一下... 目录前言什么是透视表?使用步骤1. 引入必要的库2. 读取数据3. 创建透视表4. 查看透视表总结前言