Let's find the most negative and the most positive (ignoring self-correlation) values
from pandas import DataFrame
from sklearn.datasets import fetch_california_housing
housing_data = fetch_california_housing()
housing = DataFrame(housing_data.data, columns=housing_data.feature_names)
corr = housing.corr()
corr
Find the most negative correlation for each column:
corr.min()
Find the column which has the lowest correlation:
corr.min().idxmin()
Extract the Latitude column and get the index of the most negative value in it:
corr[corr.min().idxmin()].idxmin()
The most negative correlation is therefore between:
corr.min().idxmin(), corr[corr.min().idxmin()].idxmin()
with the value:
corr.min().min()
First we need to remove the 1.0 values on the diagonal:
import numpy as np
np.fill_diagonal(corr.values, np.nan)
corr
corr.max().idxmax(), corr[corr.max().idxmax()].idxmax()
corr.max().max()