如何获得仅列出绝对值相关性大于.7的变量的输出?
我想要类似以下的输出:
four: one, three
one: three
谢谢你的时间!
代码
import pandas as pd
x={'one':[1,2,3,4],'two':[3,5,7,5],'three':[2,3,4,9],'four':[4,3,1,0],}
y=pd.DataFrame(x)
print(y.corr())
输出
four one three two
four 1.000000 -0.989949 -0.880830 -0.670820
one -0.989949 1.000000 0.913500 0.632456
three -0.880830 0.913500 1.000000 0.262613
two -0.670820 0.632456 0.262613 1.000000
如果您只想打印出来,这将起作用:
col_names = y.corr().columns.values
for col, row in (y.corr().abs() > 0.7).iteritems():
print(col, col_names[row.values])
请注意,这可行,但是可能会很慢,因为该iteritems
方法将每一行都转换为一系列。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句