Skip to content

Instantly share code, notes, and snippets.

@sillasgonzaga
Last active April 13, 2020 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sillasgonzaga/e82f2d14d3619d9c58dc74145aa8aeee to your computer and use it in GitHub Desktop.
Save sillasgonzaga/e82f2d14d3619d9c58dc74145aa8aeee to your computer and use it in GitHub Desktop.
def correl_df(dframe):
correl_matrix = dframe.corr()
# Select upper triangle of correlation matrix
upper = correl_matrix.where(np.triu(np.ones(correl_matrix.shape), k=1).astype(np.bool)).head()
upper = upper.unstack().reset_index()
# rename columns
upper.columns = ['var1', 'var2', 'correl']
# drop na
upper = upper.dropna()
upper['correl_abs'] = np.abs(upper['correl'])
return(upper.sort_values(by = 'correl_abs', ascending = False))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment