将直方图和核密度函数放在一张图上,有两种方式,1.使用pandas自带的工具绘制 2. 使用seaborn库绘制
1.使用pandas自带的工具绘制(设置density = True)
#导包
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# 数据加载
data = pd.read_csv('D:/Download/bankpep.csv')
data.head()
# 客户年龄分布的直方图和密度图
data.age.plot.hist(density = True,bins = 9)
data.age.plot(kind='kde',title = "KDE of the distribution of customers' age")
plt.title( "Histogram of the distribution of customers' age")
plt.show()
2. 使用seaborn库绘制
import seaborn as sns
sns.distplot(data.age)
欢迎 : 转发+评论+点赞哟~~
谢谢支持 (*^▽^*)~~!