Pivot over several types of columns at the same time

I have a dataframe that looks something like this:

|  ID  |   Vars   |   baseline   |  timepoint1  | timepoint2  |
|  1   |    a     |      1       |      1       |      1      |
|  1   |    b     |      2       |      2       |      2      |
|  1   |    c     |      3       |      3       |      3      |
|  2   |    a     |      4       |      4       |      4      |
|  2   |    b     |      5       |      5       |      5      |
|  2   |    c     |      6       |      6       |      6      |
|  3   |    a     |      7       |      7       |      7      |

What I want is to have a unique ID, so I would have a column for the combination of vars and timepoints.

It would look like this:

|  ID  |   Varsa_baseline   |  Varsb_baseline   |  Varsc_baseline  | Varsa_timepoint1  |
|  1   |      1             |      2            |     3            |      1            |
|  2   |      4             |      5            |     6            |      6            | 

I though about using pivoting, but I couldn’t manage to solve it yet

Hi @RoyBatty296

You can try something like this pivot_over_several_types_of_columns.knwf (32.1 KB).
Schermafdruk van 2022-01-06 13-12-30
gr. Hans

1 Like

save

seems to work as well but kudos to @HansS . I always enjoy seeing his workflows and way of doing thinks. Highly appreciate your knowledge sharing here.
br

2 Likes

Tnx Daniel, much appreciated!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.