0

I'm looking to use python to pivot values from one row into new columns, and then combine the rows. For example:

Name Random info Role Name
A Yada Owner Bob
A Yada Approver Jimmy
B Nada Owner Sally
B Nada Approver Susie

Would become this:

Name Random Info Owner Approver
A Yada Bob Jimmy
B Nada Sally Susie

What's the best way to do this?

I tried using the pivot functions available in pandas, but I kept getting different errors because I don't think my data is structured correctly compared to what the function is expecting.

  • Something like `df.pivot(index=["Name", "Random info"], columns="Role", values="Name.1")` should work (mind the duplicate column label `Name`) – Chrysophylaxs Mar 01 '23 at 20:25
  • 1
    Classic SO post on pivoting: https://stackoverflow.com/questions/47152691/how-can-i-pivot-a-dataframe – Chrysophylaxs Mar 01 '23 at 20:25

0 Answers0