1、读取数据
data=pd.read_excel(r'C:\Users\Administrator\Desktop\1_20191021评分卡解析.xlsx')
2、提取需要计算相关系数的列
a=data.ix[:,6:].corr()
3、画热力图
import matplotlib.pyplot as plt
import seaborn as sns
plt.subplots(figsize=(9, 9))
sns.heatmap(a, annot=True, vmax=1, square=True, cmap="Blues")
plt.show()
4、结果如图

1、用来正常显示中文标签
plt.rcParams[‘font.sans-serif’]=[‘FangSong’]
2、用来正常显示负号
plt.rcParams[‘axes.unicode_minus’]=False
本文介绍如何使用Python的pandas库读取Excel数据,通过计算相关系数矩阵分析变量间的相关性,并利用seaborn库绘制热力图进行直观展示。此外,还介绍了如何设置matplotlib参数以正确显示中文标签和负号。
11万+

被折叠的 条评论
为什么被折叠?



