df1 = pd.DataFrame({'foo': ['one', 'one', 'one', 'two', 'two', 'two'],
'bar': ['A', 'B', 'C', 'A', 'B', 'C']})
| foo | bar | |
|---|---|---|
| 0 | one | A |
| 1 | one | B |
| 2 | one | C |
| 3 | two | A |
| 4 | two | B |
| 5 | two | C |
I would like to convert this to
| foo | val1 | val2 | val3 |
|---|---|---|---|
| One | A | B | C |
| Two | A | B | C |
And the code I tried is:
pd.pivot_table(df1,index='foo',aggfunc=['first'])
But the above code is returning only the first value