使用函数计算许多行

时间:2018-09-04 07:03:01

标签: python pandas csv

我想问你所有如何计算每个ID之间的收益或利差。想要使用诸如定义功能等功能。

示例:id 1和2的每个之间的差异; id 1和2的每个收盘之间的差异。

非常感谢。

Here is the image

1 个答案:

答案 0 :(得分:0)

我会将您的数据转换为Pandas数据框,然后使用diff()函数。这是您要找的吗?

df = pd.DataFrame({'Open': [187.88, 185.14, 186.35, 187.25],
                   'High': [189.22, 186.33, 187.2, 188.35],
                   'Low': [187.2, 183.45, 185.73, 184.94]}, index=range(1, 5))
df.index.name = 'ID'
spread = df.diff()
相关问题