📜  一列与所有其他列之间的 pandas 相关矩阵 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:05.487000             🧑  作者: Mango

代码示例1
correlations = df.corr().unstack().sort_values(ascending=False) # Build correlation matrix
correlations = pd.DataFrame(correlations).reset_index() # Convert to dataframe
correlations.columns = ['col1', 'col2', 'correlation'] # Label it
correlations.query("col1 == 'v2' & col2 != 'v2'") # Filter by variable
# output of this code will give correlation of column v2 with all the other columns