List Highest Correlation Pairs from a Large Correlation Matrix in Pandas?

后端 未结 13 538
心在旅途
心在旅途 2020-12-22 17:45

How do you find the top correlations in a correlation matrix with Pandas? There are many answers on how to do this with R (Show correlations as an ordered list, not as a lar

13条回答
  •  死守一世寂寞
    2020-12-22 18:29

    Combining some features of @HYRY and @arun's answers, you can print the top correlations for dataframe df in a single line using:

    df.corr().unstack().sort_values().drop_duplicates()
    

    Note: the one downside is if you have 1.0 correlations that are not one variable to itself, the drop_duplicates() addition would remove them

提交回复
热议问题