在 python pandas 中,shift 函数可用于将数据帧中的行向前移动,并且可能相对于原始数据进行移动,这允许计算时间序列数据的变化。Julia中的等效方法是什么?
问问题
362 次
2 回答
6
通常人们会使用ShiftedArrays.jl并将其应用于需要移位的列。
于 2020-10-27T21:14:57.333 回答
2
Here is a small working example:
using DataFrames, ShiftedArrays
df = DataFrame(a=1:3, b=4:6)
3×2 DataFrame
Row │ a b
│ Int64 Int64
─────┼──────────────
1 │ 1 4
2 │ 2 5
3 │ 3 6
transform(df, :a => lag => :lag_a)
3×3 DataFrame
Row │ a b lag_a
│ Int64 Int64 Int64?
─────┼───────────────────────
1 │ 1 4 missing
2 │ 2 5 1
3 │ 3 6 2
or you could do:
df.c = lag(df.a)
or, to have the lead of two rows:
df.c = lead(df.a, 2)
etc.
于 2022-01-22T15:49:25.700 回答