0

I have a Dataframe in the following format:


index      id           employee    date            week      result
1          1234565      Max         2022-07-04      27        Project 1
2          1234565      Max         2022-07-04      27        Task 1
3          1234565      Max         2022-07-04      27        Full-Time
4          1256391      Susanne     2022-07-05      27        Project 2                         
5          1256391      Susanne     2022-07-05      27        Task 2
6          1256391      Susanne     2022-07-05      27        Full-Time

What I want to achieve is the following format:

index      id           employee    date            week      result        task       status
1          1234565      Max         2022-07-04      27        Project 1     Task 1     Full-Time
2          1256391      Susanne     2022-07-05      27        Project 2     Task 2     Full-Time 
                                           

So the logic is, that always 3 rows belong together. Is there any way to achieve the desired outcome? Besides the Index column, there is not a unique index.

Treemaster
  • 23
  • 2
  • create helper columns `df['new'] = df.index // 3 + 1` and then use `pivot` – jezrael Jul 19 '22 at 07:41
  • I've tried it, but it brings not the desired outcome. I have created a helping column with worked well, but creating the Pivot was not working as expected. Am I missing something? df.pivot(index=['id','employee','date','week','new'], columns='result', values='result') – Treemaster Jul 19 '22 at 08:39
  • what is your pivot code? – jezrael Jul 19 '22 at 08:40
  • df.pivot(index=['id','employee','date','week','new'], columns='result', values='result') – Treemaster Jul 19 '22 at 08:43
  • change columns='new' – jezrael Jul 19 '22 at 08:56
  • Then I get an error: Index contains duplicate entries, cannot reshape. If I add the 'index' column to the pivot index, it is writing all the entries from "new" next to each other, so the table gets very big – Treemaster Jul 19 '22 at 09:21

0 Answers0