I have a simple dataset that I want to do a rolling operation on. The dataset looks like this:
user_id create_at v1
0 15991247 2022-05-31 21:00:21.150822 0.028059
1 24062521 2022-05-31 21:00:33.620000 1.781399
2 12610025 2022-05-31 21:01:30.349000 0.952400
3 24062521 2022-05-31 21:02:38.836000 1.571899
4 24062521 2022-05-31 21:02:44.156000 0.952600
When I attemp to do a rolling operation,
d1 = d1.set_index('create_at')
d1.groupby('user_id')['v1'].rolling('3D').sum().reset_index(drop = True)
I get the correct answer:
0 -0.083971
1 -0.139826
2 1.941623
3 1.169590
4 0.313641
...
But when I attemp to attach it back to the dataset everything becomes NaN, i.e.
d1['roll_3D'] = d1.groupby('user_id')['v1'].rolling('3D').sum().reset_index(drop = True)
user_id v1 roll_3D
create_at
2022-05-31 21:00:21.150822 15991247 0.028059 NaN
2022-05-31 21:00:33.620000 24062521 1.781399 NaN
2022-05-31 21:01:30.349000 12610025 0.952400 NaN
2022-05-31 21:02:38.836000 24062521 1.571899 NaN
2022-05-31 21:02:44.156000 24062521 0.952600 NaN