从数据框创建热图

时间:2019-10-20 23:31:38

标签: pandas group-by data-science

如何为YearStateEngine的颜色制作热图?

Year    Make    Engine  State          Tally
2012    Acura   2.4     Rhode Island    1
2013    Acura   3.5     Rhode Island    1
2012    Acura   1.8     Rhode Island    1
2013    Acura   2.4     Rhode Island    1
2015    Acura   2.4     Rhode Island    1
2016    Acura   2.4     Rhode Island    1
2015    Acura   3       Rhode Island    1
2017    Acura   1.8     Rhode Island    1

1 个答案:

答案 0 :(得分:0)

import pandas as pd  
import seaborn as sns   
import matplotlib.pyplot as plt  

heatmapdata = pd.pivot_table(df, values='Engine', index=['State'], columns='Year')
sns.heatmap(heatmapdata, cmap="YlOrRd")

df是数据框的名称。