Existing Dataframe :
UserId Activity_date Time_stamp
A 27-01-2022 13:00:00
A 27-01-2022 15:00:00
A 27-01-2022 16:00:00
A 28-01-2022 09:00:00
A 28-01-2022 11:00:00
Expected Dataframe :
UserId Activity_date Time_stamp Difference_of_time_stamp
A 27-01-2022 13:00:00 -
A 27-01-2022 15:00:00 02:00:00
A 27-01-2022 16:00:00 01:00:00
A 28-01-2022 09:00:00 -
A 28-01-2022 11:00:00 02:00:00
Difference of time(in milliseconds) needs to be calculated. i am currently using groupby on the UserId and Activity_date so that the difference of time should be calculated for that specific date only.
i know this can be used to get the difference of timestamp but how to groupby on Activity_date
df.assign(Difference_of_time=df.groupby('UserId').Time_stamp.apply(lambda x: x - x.iloc[0]))