I have a pandas dataframe and would like to split each row containing multiple tasks into a new row.
The dataframe columns are:
start_t_i = start time of a task.
end_t_i = end time of a task.
weight_i = cost of a task.
For example, suppose I have the following dataframe df1:
| task_name | start_t1 | end_t1 | weight_1 | start_t_2 | end_t2 | weight_2.. | start_t_k | end_t_k | weight_k |
|---|---|---|---|---|---|---|---|---|---|
| john | 5 | 7 | 1 | 9 | 10 | 9 | |||
| sally | 3 | 4 | 1 | 8 | 11 | 7 | 19 | 21 | 1 |
| tom | 1 | 2 | 3 |
I would like to transform it into the following df2:
| task_name | start_t | end_t | weight |
|---|---|---|---|
| john | 5 | 7 | 1 |
| john | 9 | 10 | 9 |
| sally | 3 | 4 | 1 |
| sally | 8 | 11 | 7 |
| sally | 19 | 21 | 1 |
| tom | 1 | 2 | 3 |
so far I managed to transform df1 manually into df2 by assuming each person has only a maximum of two tasks. my question is how can I get a df such as df2 from df1 when there are up to k tasks for each person.