0

I am trying to convert the following dataframe with multiple rows (table 1) into multiple columns (table 2) efficiently. Therefore, I am trying to do it without using for loop iterating through all PKs. Can anyone help?

table 1

|--------------|-------------|
|      PK      |     Name    |
|--------------|-------------|
|      PK1     |      a      |
|--------------|-------------| 
|      PK1     |      b      |
|--------------|-------------|
|      PK2     |      c      |
|--------------|-------------|
|      PK1     |      d      | 
|--------------|-------------| 
|      PK2     |      e      | 
|--------------|-------------|                    

table 2

|--------------|--------------|--------------|--------------|
|      PK      |     Name1    |     Name2    |     Name3    |
|--------------|--------------|--------------|--------------|
|      PK1     |       a      |       b      |       d      |
|--------------|--------------|--------------|--------------|
|      PK2     |       c      |       e      |      NaN     |
|--------------|--------------|--------------|--------------|                   
Young
  • 1

0 Answers0