Reputation: 347
I need to do a pivot aggregation filling columns with answer.
Here below the example, thank u!
Input
id | question | answer |
---|---|---|
1 | quest_1 | Good |
1 | quest_2 | Bad |
2 | quest_1 | Bad |
2 | quest_2 | Good |
2 | quest_3 | Quite Good |
Output
id | quest_1 | quest_2 | quest_3 |
---|---|---|---|
1 | Good | Bad | NULL |
2 | Bad | Good | Quite Good |
Upvotes: 1
Views: 196
Reputation: 26676
Do a pivot
df.groupby('id').pivot('question').agg(first('answer')).show()
Upvotes: 1