Skip to content

Instantly share code, notes, and snippets.

@shashankvemuri
Last active September 15, 2020 02:18
Show Gist options
  • Save shashankvemuri/de9388a5a7e78644f0b5ac2f6b3bd3bd to your computer and use it in GitHub Desktop.
Save shashankvemuri/de9388a5a7e78644f0b5ac2f6b3bd3bd to your computer and use it in GitHub Desktop.
functions
def get_redundant_pairs(df):
pairs_to_drop = set()
cols = df.columns
for i in range(0, df.shape[1]):
for j in range(0, i+1):
pairs_to_drop.add((cols[i], cols[j]))
return pairs_to_drop
def get_top_abs_correlations(df):
au_corr = df.corr().abs().unstack()
labels_to_drop = get_redundant_pairs(df)
au_corr = au_corr.drop(labels=labels_to_drop).sort_values(ascending=False)
return au_corr
print("\nTop Absolute Correlations")
print(get_top_abs_correlations(stocks_returns))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment