I have the following data:
machine_id time_to_failure
430494 1000
430494 700
430494 500
430494 100
430495 1000
430495 200
The time to failure data is counted from a reference day 0 and I would like to turn it into the time since the previous failure:
machine_id time_to_failure
430494 300
430494 200
430494 400
430494 100
430495 800
430495 200
I tried using groupby and pivoting duplicate rows into new columns for the subtraction. However, I would like to do it in place to preserve other columns.