Skip to content

Instantly share code, notes, and snippets.

@monkey-codes
Created June 18, 2018 04:18
Show Gist options
  • Select an option

  • Save monkey-codes/1aeb07a7bd498ceb12d6da58fdf3b3d0 to your computer and use it in GitHub Desktop.

Select an option

Save monkey-codes/1aeb07a7bd498ceb12d6da58fdf3b3d0 to your computer and use it in GitHub Desktop.
How to get do a rank correlation using python
#df - pandas dataFrame
fromfrom scipy.clusterscipy.cl import hierarchy as hc
corr = np.round(scipy.stats.spearmanr(df).correlation, 4)
corr_condensed = hc.distance.squareform(1-corr)
z = hc.linkage(corr_condensed, method='average')
fig = plt.figure(figsize=(16,10))
dendrogram = hc.dendrogram(z, labels=df_keep.columns, orientation='left', leaf_font_size=16)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment