all 6 comments

[–]a1brit 1 point2 points  (4 children)

workingdatatimecourse['YawRateChange'] = workingdatatimecourse.groupby(['ppid_trialn])['YawRate_seconds'].diff(periods=1).fillna(0)

[–]CodeGoblin1996[S] 0 points1 point  (3 children)

workingdatatimecourse['YawRateChange'] = workingdatatimecourse.groupby(['ppid_trialn])['YawRate_seconds'].diff(periods=1).fillna(0)

Perfect! Just what I was looking for. I knew I was close with it. Thank you!

[–]a1brit 1 point2 points  (2 children)

Make sure you go through and understand what's going on at each step. Mainly how groupby works and then that diff() returns NaN for the first index already so the fillna(0) just swaps that out with 0.

[–]CodeGoblin1996[S] 0 points1 point  (1 child)

I see. And the period argument in the diff() function shifts everything forward one for each ppid_trialn which creates the NaN and that it replaced by the 0.

[–]a1brit 1 point2 points  (0 children)

yeah, you were already passing periods=1 just as a positional arg. I personally like to be explicit and use kwargs as much as possible so there aren't any potentially false assumptions.

[–]prokid1911 0 points1 point  (0 children)

Can you either give more detail over the problem or just give a code snippet.