-1

python pandas dataframe representation in notepad

This is a dataframe of countries and the count of cars each country has. It's preferred to have countries on the left/y axis and cars as bottom/x axis.

TheEngineer
  • 31
  • 1
  • 6
  • Did you try this? https://stackoverflow.com/questions/12286607/making-heatmap-from-pandas-dataframe – xszym Jun 28 '20 at 09:06
  • Kindly refer to this.[seaborn.heatmap](http://alanpryorjr.com/visualizations/seaborn/heatmap/heatmap/) – r-beginners Jun 28 '20 at 09:08

1 Answers1

1

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

OUTPUT: #2 enter image description here

Kaustubh Lohani
  • 635
  • 5
  • 15