I have gone through Convert columns into rows with Pandas and Merge timestamp column in pandas
, the goal is to first group data by ID
and then convert start_time
column into an entity in the process column
Given
start_time time process ID
14:05 14:16 A 1
14:05 14:34 B 1
14:05 15:00 C 1
14:05 15:10 D 1
14:12 14:19 A 2
14:12 14:54 B 2
Goal
time process ID
14:05 start_time 1 (Previously it was in separate column)
14:16 A 1
14:34 B 1
15:00 C 1
15:10 D 1
14:12 start_time 2
14:19 A 2
14:54 B 2
df.groupby('ID').melt(df.columns.difference(['start_time']), value_name='time')
Note:start_time
value in each ID remains the same.