Last active
April 13, 2020 22:30
-
-
Save sillasgonzaga/e82f2d14d3619d9c58dc74145aa8aeee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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