xxxxxxxxxx
import seaborn as sns
#load the dataset
df = sns.load_dataset('iris')
#calculate correlation
corr_matrix = df.corr('pearson') #kind of correlation-> ‘pearson’, ‘kendall’, ‘spearman’
#plot correlation
corr_matrix.style.background_gradient(cmap='coolwarm')
# 'RdBu_r', 'BrBG_r', & PuOr_r are other good diverging colormaps
xxxxxxxxxx
# Basic syntax:
dataframe1["col_name1"].corr(dataframe2["col_name2"], method="pearson")
# Where:
# - this calculates the Pearson's correlation between the specified columns
# in each dataframe (which can also be the same dataframe)
# - the method indicates the type of correlation to perform, others include:
# kendall: The Kendall Tau correlation coefficient
# spearman: The Spearman rank correlation