Ale*_*lan 4 python numpy ipython pandas
我有一个数据帧,看起来像这样:每个值代表5个距离(1000m,800m,600m,400m,200m,0)之一的值。
'key1': array([ 1.21, 0.99, 6.66,
5.22, 3.33]), 'key2': array([ 2.21, 2.99, 5.66,
6.22, 2.33]), 'key3': array([ 4.21, 1.59, 6.66,
9.12, 0.23])......
Run Code Online (Sandbox Code Playgroud)
我想计算每个键的值和距离之间的Spearman等级相关性。
我有很多“键”,我想以某种方式在熊猫中做到这一点。然后绘制所有键上Spearman等级和平均距离的图表。
由于您提到了熊猫,因此熊猫在方法中具有corr功能 spearman
pd.concat([pd.DataFrame(v),pd.DataFrame(d)],axis=1).corr(method="spearman").iloc[-1]
Out[1302]:
key1 -0.5
key2 -0.4
key3 0.1
0 1.0
Name: 0, dtype: float64
Run Code Online (Sandbox Code Playgroud)