【发布时间】:2018-12-30 09:34:13
【问题描述】:
我有两个熊猫数据框:价格和销售数据框。
价格数据框记录每年(索引)中每种产品(列)的价格
|a |b |c |d |e |
2018|3.2|4.5|5.6|7.8|8.1|
2017|6.2|1.5|2.6|7.8|2.1|
2016|2.2|9.5|0.6|6.8|4.1|
2015|2.2|6.5|7.6|7.8|2.1|
销售数据框(见下文)记录每年(索引)中每种产品(列)的销售额
|a |b |c |d |e |
2018|101|405|526|108|801|
2017|601|105|726|308|201|
2016|202|965|856|408|411|
2015|322|615|167|458|211|
我想计算每年价格和销售额之间的 spearman 相关性。我知道 scipy.stats.spearmanr 函数做了类似的工作,但我需要为两个数据帧中的每一行应用 scipy.stats.spearmanr 函数。
例如,对于 2018 年,我需要计算两者之间的 spearman 相关性
|a |b |c |d |e |
2018|3.2|4.5|5.6|7.8|8.1|
和
|a |b |c |d |e |
2018|101|405|526|108|801|
我可以知道什么是最好的吗? 结果我想要如下输出:
2018|spearman cor btw price and sales in 2018
2017|spearman cor btw price and sales in 2017
2016|spearman cor btw price and sales in 2016
【问题讨论】: