一些小提示和小技巧可能是非常有用的,特别是在编程领域。有时候使用一点点黑客技术,既可以节省时间,还可能挽救“生命”。
一个小小的快捷方式或附加组件有时真是天赐之物,并且可以成为真正的生产力助推器。所以,这里有一些小提示和小技巧,有些可能是新的,但我相信在下一个数据分析项目中会让你非常方便。
Pandas中数据框数据的Profiling过程
Profiling(分析器)是一个帮助我们理解数据的过程,而Pandas Profiling是一个Python包,它可以简单快速地对Pandas 的数据框数据进行探索性数据分析。
Pandas中df.describe()和df.info()函数可以实现EDA过程第一步。但是,它们只提供了对数据非常基本的概述,对于大型数据集没有太大帮助。 而Pandas中的Profiling功能简单通过一行代码就能显示大量信息,且在交互式HTML报告中也是如此。
对于给定的数据集,Pandas中的profiling包计算了以下统计信息:
由Pandas Profiling包计算出的统计信息包括直方图、众数、相关系数、分位数、描述统计量、其他信息——类型、单一变量值、缺失值等。
安装
用pip安装或者用conda安装
<span style="max-width: 1000%;"><span style="max-width: 1000%;">pip</span> <span style="max-width: 1000%;">install pandas-profiling</span></span>
<span style="max-width: 1000%;"> <span style="max-width: 1000%;">conda</span> <span style="max-width: 1000%;">install -c anaconda pandas-profiling</span></span>
用法
下面代码是用很久以前的泰坦尼克数据集来演示多功能Python分析器的结果。
<span style="max-width: 1000%;">#importing the necessary packages</span>
<span style="max-width: 1000%;"> <span style="max-width: 1000%;">import</span> pandas <span style="max-width: 1000%;">as</span> pd</span>
<span style="max-width: 1000%;"> <span style="max-width: 1000%;">import</span> pandas_profiling</span>
<span style="max-width: 1000%;">df = pd.read_csv(<span style="max-width: 1000%;">'titanic/train.csv'</span>)</span>
<span style="max-width: 1000%;"> pandas_profiling.ProfileReport(df)</span>
一行代码就能实现在Jupyter Notebook中显示完整的数据分析报告,该报告非常详细,且包含了必要的图表信息。
还可以使用以下代码将报告导出到交互式HTML文件中。
<span style="max-width: 1000%;">profile = pandas_profiling.ProfileReport(df)</span>
<span style="max-width: 1000%;">profile.to_file(outputfile=<span style="max-width: 1000%;">"Titanic data profiling.html"</span&g