0

I have a table which e.g. looks like this

Food Compound Content in grams
Kiwi Fat 5
Kiwi Protein 3
Apple Protein 2

I want to pivot it with pandas, so that it looks like

Food Fat Protein
Kiwi 5 3
Apple 2 0

Thanks in Advance!

  • Please provide enough code so others can better understand or reproduce the problem. – Community Sep 14 '22 at 09:15
  • **Reproducing the problem:** `df = pd.DataFrame({"Food":["Kiwi","Kiwi","Apple"], "Compound":["Fat","Protein","Protein"], "Content in grams":[5,3,2]})` **Pivoting:** `df.pivot(index = 'Food', columns='Compound',values='Content in grams').reset_index()` – Nikos Maniaths Sep 14 '22 at 10:18

0 Answers0