使用 python Pandas Profiling 進行EDA 探索性數據分析

作者:season



探索性數據分析

數據的篩選、重組、結構化、預處理等都屬於探索性數據分析的範疇,探索性數據分析是幫助數據分析師掌握數據結構的重要工具,也是奠定後續工作的成功基石。

在數據的分析項目中,數據的收集和預處理往往佔據整個項目工作量的十之八九。


Generates profile reports from a pandas DataFrame. The pandas df.describe() function is great but a little basic for serious exploratory data analysis. pandas_profiling extends the pandas DataFrame with df.profile_report() for quick data analysis.

For each column the following statistics - if relevant for the column type - are presented in an interactive HTML report:

Essentials: type, unique values, missing values
Quantile statistics like minimum value, Q1, median, Q3, maximum, range, interquartile range
Descriptive statistics like mean, mode, standard deviation, sum, median absolute deviation, coefficient of variation, kurtosis, skewness
Most frequent values
Histogram
Correlations highlighting of highly correlated variables, Spearman, Pearson and Kendall matrices
Missing values matrix, count, heatmap and dendrogram of missing values

官網:https://github.com/pandas-profiling/pandas-profiling


代碼樣例

一個完整的樣例:
https://nbviewer.jupyter.org/github/lksfr/TowardsDataScience/blob/master/pandas-profiling.ipynb

# importing required packages
import pandas as pd
import pandas_profiling
import numpy as np


# importing the data
df = pd.read_csv('/Users/lukas/Downloads/titanic/train.csv')

profile = pandas_profiling.ProfileReport(tijian_pdf)
profile.to_file("output_tijian_chinese.html")

效果

樣例鏈接:https://pandas-profiling.github.io/pandas-profiling/examples/meteorites/meteorites_report.html
在這裏插入圖片描述
在使用過程中發現,中文顯示有問題,下面這塊應該是調用seaborn 完成的。我們從源碼配置文件可以看到
在這裏插入圖片描述

在這裏插入圖片描述

解決pandas profile 中文顯示的問題

我們找到 pandas porfile 的配置文件,在conda 的環境中:

路徑爲:

D:\ProgramData\Anaconda3\envs\DATABASE\Lib\site-packages\pandas_profiling\view

在這裏插入圖片描述

打開文件看到:

## Credits for this style go to the ggplot and seaborn packages.
##   I copied the style file to remove dependencies on the Seaborn package.
##   Check it out, it's an awesome library for plotting!

其實設置是參照seaborn ,但是pandas profile 的繪圖設置是獨立於seaborn 的。
所以在字體設置(籃筐處),加上一個漢語字體,其他的字體幹掉,注意前後空格,ok。

在這裏插入圖片描述

以防萬一,把字體文件在這個目錄再放一份
在這裏插入圖片描述
打完收工!

思路參考:

以 matplotlib 爲基礎的庫的可視化庫的中文顯示問題,都可以這麼設置


發佈了35 篇原創文章 · 獲贊 7 · 訪問量 9482
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章