0

I have a dataframe of type:

a = ['a','b','c','a','b','c','a','b','c']
b = [0,1,2,3,4,5,6,7,8]
df = pd.DataFrame({'key':a,'values':b})

  key  values
0   a       0
1   b       1
2   c       2
3   a       3
4   b       4
5   c       5
6   a       6
7   b       7
8   c       8

I want to move the values in the "values" column to new columns where they have the same "key".

So result:

  key  values0  values1  values2
0   a        0        3        6
1   b        1        4        7
2   c        2        5        8

I tried using

pd.merge(d1,d1['values'], on=d1['key'])

because I think I need to merge (or join?) them on the d1['key'] column

Mitch
  • 343
  • 3
  • 16

0 Answers0