I have a pearson correlation heat map coded, but its showing data from my dataframe which i dont need.
is there a way to specify which columns i’d like to include?
thanks in advance
JavaScript
x
9
1
sb.heatmap(df['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL'].corr(), annot=True, fmt='.2f')
2
3
---------------------------------------------------------------------------
4
TypeError Traceback (most recent call last)
5
<ipython-input-54-832fc3c86e3e> in <module>
6
----> 1 sb.heatmap(df['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL'].corr(), annot=True, fmt='.2f')
7
8
TypeError: list indices must be integers or slices, not tuple
9
JavaScript
1
8
1
df.cov().round(3)
2
---------------------------------------------------------------------------
3
TypeError Traceback (most recent call last)
4
<ipython-input-79-34a86e96b161> in <module>
5
----> 1 df.cov().round(3)
6
7
TypeError: cov() missing 1 required positional argument: 'self'
8
Advertisement
Answer
You can filter the dataframe before calculating correlation
JavaScript
1
2
1
sns.heatmap(df[['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL']].corr(), annot=True, fmt='.2f')
2