0

I have a dataframe that looks like this:

Input dataframe

How can I use pandas in order to transform the dataframe into this:

Output dataframe

Thank you for your help :)

Tried using unstack() but couldn't figure it out.

Ben Grossmann
  • 4,387
  • 1
  • 12
  • 16
aglm
  • 1
  • 1
  • This is exactly what the pivot function is made for. If `df` is your dataframe variable, you should be able to do `result = df.pivot(index = 'Case', columns = 'Device', values = 'Value')`. You could use the unstack function similarly, but you would first have to make the first two columns of your dataframe into a multiindex – Ben Grossmann Mar 07 '23 at 13:05

0 Answers0