0

I have a dataframe that looks like this:

A type val
first B 20
second B 30
first C 200
second C 300

I need to get it to look like this:

A B C
first 20 200
second 30 300

How do I do this using Pandas? I tried using transpose, but couldn't get it to this exact table.

mirkap
  • 7
  • 1
  • 4

1 Answers1

0
df = df.pivot('A','type')
df.columns = [x[1] for x in list(df.columns)]
df.reset_index()
MoRe
  • 2,296
  • 2
  • 3
  • 23