Instead of drawing separate scatterplots to find the correlation strength between the happiness score and variables such as freedom, generosity, family etc
I am trying to construct a correlation matrix as a heatmap using the code below but it is not working please advise on what is wrong?
I am trying to edit code I found here
https://datatofish.com/correlation-matrix-pandas/
I also tried following along from here
It is using the world happiness datasets from the below link
import seaborn as sn
import seaborn as sn
import numpy as np
%matplotlib inline
df = pd.Dataframe(happiness2015['Freedom','Generosity','Happiness Score','Trust (Government Corruption)'])
df.pivot(index='Happiness Score',columns='Freedom','Generosity','Trust (Government Corruption)')
corrMatrix = df.corr()
sn.heatmap(corrMatrix,annot=True)
plt.show()
I also just tried doing pivot but I did not get as far as that since it returned error
df = pd.Dataframe(happiness2015['Freedom','Generosity','Happiness Score','Trust (Government Corruption)'])
df.pivot(index='Happiness Score',columns='Freedom','Generosity','Trust (Government Corruption)')
As I understand the index param sets the column to use to make new frame’s index which I want to be the happy score, but this returns error.
File “”, line 8
df.pivot(index=‘Happiness Score’,columns=‘Freedom’,‘Generosity’,‘Trust (Government Corruption)’)
^
SyntaxError: positional argument follows keyword argument