My dataframe is:
id beg end
client1 2021-10-19 16:01:01 2021-10-21 08:19:17
client1 2021-10-21 10:41:53 2021-10-24 07:53:57
client3 2021-10-21 09:00:00 2021-10-21 10:00:00
client3 2021-10-21 10:00:00 2021-10-22 14:00:00
client2 2021-10-21 10:00:00 2021-10-21 14:00:00
I want to add columns based on previous value of column by id as shown below.
If the client appears more than once then I want to create new columns on the second appearance of this client...
col1that takes the previousendcol2that takes the currentbegof this row (in this example, for client1 and client3).
...else put nothing in col1, col2
Expected output:
id beg end col1 col2
client1 2021-10-19 16:01:01 2021-10-21 08:19:17 - -
client1 2021-10-21 10:41:53 2021-10-24 07:53:57 2021-10-21 08:19:17. 2021-10-21 10:41:53
client3 2021-10-21 09:00:00 2021-10-21 10:00:00 -- --
client3 2021-10-21 10:00:00 2021-10-22 14:00:00 2021-10-21 10:00:00 2021-10-21 10:00:00
client2 2021-10-21 10:00:00 2021-10-21 14:00:00 2021-10-21 10:00:00 2021-10-21 14:00:00