How to make a correlation matrix in python

Published: 20 March 2024
on channel: Karina Adcock
11,201
233

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

data = pd.read_excel("C:/Users/Karina Adcock/Documents/data analysis/samples/data.xlsx","Sheet1")

my_matrix = data.corr(method="spearman").round(2)

#my_matrix.style.background_gradient(cmap="Greens")

#pd.plotting.scatter_matrix(my_matrix, figsize=(8,8))

my_mask = np.triu(np.ones_like(my_matrix,dtype=bool))

plt.figure(figsize=(10,8)) #width, height
sns.heatmap(my_matrix, cmap="Blues", vmin=0, vmax=1,
annot=True, fmt="0.2f", square=True, mask=my_mask)

plt.show()


https://pandas.pydata.org/docs/refere...

https://r02b.github.io/seaborn_palettes/

https://seaborn.pydata.org/generated/...


On this page of the site you can watch the video online How to make a correlation matrix in python with a duration of hours minute second in good quality, which was uploaded by the user Karina Adcock 20 March 2024, share the link with friends and acquaintances, this video has already been watched 11,201 times on youtube and it was liked by 233 viewers. Enjoy your viewing!