Skip to content
Advertisement

From unix timestamps to relative date based on a condition from another column in pandas

I have a column of dates in unix timestamps and i need to convert them into relative dates from the starting activity.

The final output should be the column D, which expresses the relative time from the activity which has index = 1, in particular the relative time has always to refer to the first activity (index=1).

JavaScript

Any idea?

Advertisement

Answer

Use to_datetime with unit='s' and then create groups starting by index equal 1 and get first value, last subtract and convert to hours:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement