0

I have a pandas dataframe like this:

a b
A 1
A 2
B 5
B 5
B 4
C 6
C 7
C 8
C 9

I would like to group by column a and put the values of column b to separate columns. Obviously I will need padding and/or clipping of the number of values, let's say if I choose 3 as max length of values and zero padding, I'd like to have the resulting dataframe like this:

a b_0 b_1 b_2
A  1   2   0
B  5   5   4
C  6   7   8

How can I achieve this with pandas / numpy?

MrTJ
  • 12,960
  • 4
  • 38
  • 62

0 Answers0