Working with Pivot table and Heatmap
My blog contains a step to step guide on working with a pivot table and heatmap on Python
The life expectancy base on continents for about 50 decades.
The graph shows Africa with the least of about (40 -56)years while Oceanic has about (72-82 )years.
analytics pythonprogramminglanguage Datasciences BigData AI machineLearning
#Importing
pandas library
import pandas as
pd
url =
'https://raw.githubusercontent.com/resbaz/r-novice-gapminder-files/master/data/gapminder-FiveYearData.csv'
#Defining
dataFrame
df1=pd.read_csv(url)
df1.head()
country
|
year
|
pop
|
continent
|
lifeExp
|
gdpPercap
|
|
0
|
Afghanistan
|
1952
|
8425333.0
|
Asia
|
28.801
|
779.445314
|
1
|
Afghanistan
|
1957
|
9240934.0
|
Asia
|
30.332
|
820.853030
|
2
|
Afghanistan
|
1962
|
10267083.0
|
Asia
|
31.997
|
853.100710
|
3
|
Afghanistan
|
1967
|
11537966.0
|
Asia
|
34.020
|
836.197138
|
4
|
Afghanistan
|
1972
|
13079460.0
|
Asia
|
36.088
|
739.981106
|
#Creating a pivot table dataframe with year along
x-axes, continent along y-axes and lifeExp filled
within cells.
df1 =
pd.pivot_table(df1,index = ["continent"], columns=
["year"], values =["lifeExp"])
#Importing
seaborn library
import seaborn
as sns
df=
sns.heatmap(df1)
The life expectancy base on continents for about 50 decades.
The graph shows Africa with the least of about (40 -56)years while Oceanic has about (72-82 )years.
analytics pythonprogramminglanguage Datasciences BigData AI machineLearning
Thanks
ReplyDeleteHello, I am not getting the last part of it which is the seaborn
ReplyDeletedf=sns.heatmap(df1)
Print df1
It shows 'seaborn has no attribute' heatmap'