I have a dataframe has two columns: unix_time and user. It has thousands of rows, this is part of it:
unix_time       user
2000000000000   A
2000000000001   A
2000000000002   B
2000000000003   B
2000000000004   B
I want to calculate how much unix_time each user spent in total by:
1. calculating time difference between rows. eg: unix_time column (row2 - row1)
2. sum the time difference if they are from the same user. eg: sum(row2 - row1) and (row3 - row2) 
output will be
time_difference_sum  user
1                    A
2                    B
I read several posts such as these two but still struggle to find a solution because I got more constraints. Any suggestions about how can I do this ? Thank you in advanced!
 
    