Pandas: Group two columns based on value in another column

Viewed 4062

I'm pretty new to python/pandas and I have a dataframe that looks something like this:

 id         name        color
id_1        alex        blue
id_2        james       yellow
id_1        sara        black
id_4        dave        pink
id_4        lin         grey
id_2        aly         red

I want to group by id and get the values in the other two columns as a list:

  id           name              color
id_1        [alex,sara]       [blue,black]
id_2        [james,aly]       [yellow,red]
id_4        [dave,lin]        [pink,grey]

Is there an easy way to do that?

1 Answers
Related