【发布时间】:2020-06-29 01:40:39
【问题描述】:
我正在制作热图。我得到了一个数据框,现在正在比较值“Age”和“purch_bike”(这是一个“是”或“否”变量)。我想清理这个视觉效果,因为热图上当前显示的值太多了。所以我想我想为年龄创建更大的范围,通过将它们分组到 11 的箱/间隔中。我该怎么做?
数据集:http://www.ishelp.info/data/bikebuyers_original.csv
当前代码和输出(通过 Google Colab):
sns.heatmap(pd.crosstab(df.Age, df.purch_bike), annot=True, fmt='d');
chi1, p_value1, dof1, expected1 = chi2_contingency(pd.crosstab(df['Age'], df['purch_bike']))
print(f'X square:\t\t{round(chi1, 4)}') # this code simply displays the Chi-square stat and p-value
print(f'p-value:\t\t{round(p_value1, 6)}')
plt.show()
【问题讨论】:
标签: python python-3.x matplotlib seaborn heatmap