Simply set the index as country
and plot the heatmap via sns.heatmap
.
Here is the code:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df=pd.DataFrame({'country':['us','france','spain','italy','germany'],
'corvette':[2,0,2,11,0],
'ford':[0,1,10,0,10],
'toyota':[1,10,0,1,1]})
df.set_index(['country'],inplace=True)
print(df) #1
ax=sns.heatmap(df,cmap='coolwarm')
plt.show() #2
OUTPUT: #1
corvette ford toyota
country
us 2 0 1
france 0 1 10
spain 2 10 0
italy 11 0 1
germany 0 10 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.