python Pandas Profiling 一行代碼EDA 探索性數據分析


1. 探索性數據分析

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

在數據的分析項目中,數據的收集和預處理每每佔據整個項目工做量的十之八九,正式這些簡單的工做決定了整個項目的成敗。python


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.git

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

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 valuesweb

官網:https://github.com/pandas-profiling/pandas-profiling數據結構


2.代碼樣例

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

# 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")

3.效果

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

在這裏插入圖片描述

4.解決pandas profile 中文顯示的問題

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

路徑爲:ui

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 爲基礎的庫的可視化庫的中文顯示問題,均可以這麼設置


本文同步分享在 博客「shiter」(CSDN)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。

相關文章
相關標籤/搜索