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

相关文章

SpringBoot分段处理List集合多线程批量插入数据方式

《SpringBoot分段处理List集合多线程批量插入数据方式》文章介绍如何处理大数据量List批量插入数据库的优化方案:通过拆分List并分配独立线程处理,结合Spring线程池与异步方法提升效率... 目录项目场景解决方案1.实体类2.Mapper3.spring容器注入线程池bejsan对象4.创建

PHP轻松处理千万行数据的方法详解

《PHP轻松处理千万行数据的方法详解》说到处理大数据集,PHP通常不是第一个想到的语言,但如果你曾经需要处理数百万行数据而不让服务器崩溃或内存耗尽,你就会知道PHP用对了工具有多强大,下面小编就... 目录问题的本质php 中的数据流处理:为什么必不可少生成器:内存高效的迭代方式流量控制:避免系统过载一次性

C#实现千万数据秒级导入的代码

《C#实现千万数据秒级导入的代码》在实际开发中excel导入很常见,现代社会中很容易遇到大数据处理业务,所以本文我就给大家分享一下千万数据秒级导入怎么实现,文中有详细的代码示例供大家参考,需要的朋友可... 目录前言一、数据存储二、处理逻辑优化前代码处理逻辑优化后的代码总结前言在实际开发中excel导入很

MyBatis-plus处理存储json数据过程

《MyBatis-plus处理存储json数据过程》文章介绍MyBatis-Plus3.4.21处理对象与集合的差异:对象可用内置Handler配合autoResultMap,集合需自定义处理器继承F... 目录1、如果是对象2、如果需要转换的是List集合总结对象和集合分两种情况处理,目前我用的MP的版本

SpringBoot 获取请求参数的常用注解及用法

《SpringBoot获取请求参数的常用注解及用法》SpringBoot通过@RequestParam、@PathVariable等注解支持从HTTP请求中获取参数,涵盖查询、路径、请求体、头、C... 目录SpringBoot 提供了多种注解来方便地从 HTTP 请求中获取参数以下是主要的注解及其用法:1

HTTP 与 SpringBoot 参数提交与接收协议方式

《HTTP与SpringBoot参数提交与接收协议方式》HTTP参数提交方式包括URL查询、表单、JSON/XML、路径变量、头部、Cookie、GraphQL、WebSocket和SSE,依据... 目录HTTP 协议支持多种参数提交方式,主要取决于请求方法(Method)和内容类型(Content-Ty

GSON框架下将百度天气JSON数据转JavaBean

《GSON框架下将百度天气JSON数据转JavaBean》这篇文章主要为大家详细介绍了如何在GSON框架下实现将百度天气JSON数据转JavaBean,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录前言一、百度天气jsON1、请求参数2、返回参数3、属性映射二、GSON属性映射实战1、类对象映

C# LiteDB处理时间序列数据的高性能解决方案

《C#LiteDB处理时间序列数据的高性能解决方案》LiteDB作为.NET生态下的轻量级嵌入式NoSQL数据库,一直是时间序列处理的优选方案,本文将为大家大家简单介绍一下LiteDB处理时间序列数... 目录为什么选择LiteDB处理时间序列数据第一章:LiteDB时间序列数据模型设计1.1 核心设计原则

Python实战之SEO优化自动化工具开发指南

《Python实战之SEO优化自动化工具开发指南》在数字化营销时代,搜索引擎优化(SEO)已成为网站获取流量的重要手段,本文将带您使用Python开发一套完整的SEO自动化工具,需要的可以了解下... 目录前言项目概述技术栈选择核心模块实现1. 关键词研究模块2. 网站技术seo检测模块3. 内容优化分析模

Java+AI驱动实现PDF文件数据提取与解析

《Java+AI驱动实现PDF文件数据提取与解析》本文将和大家分享一套基于AI的体检报告智能评估方案,详细介绍从PDF上传、内容提取到AI分析、数据存储的全流程自动化实现方法,感兴趣的可以了解下... 目录一、核心流程:从上传到评估的完整链路二、第一步:解析 PDF,提取体检报告内容1. 引入依赖2. 封装