Home > Software engineering >  pandas error: Unhashable type 'list' while pivoting table
pandas error: Unhashable type 'list' while pivoting table

Time:10-12

   This is what I have

            Country          Fruit grown       Prod(Tonnes)
            USA                Apples            100
            USA                Oranges            50
            USA             Other Fruits[]        60  
            India              Apples              200
            India              Oranges             50
            India           Other Fruits[]        50

    This is what I want 

            Country         Fruits      
                             Apples   Oranges   Other Fruits

               USA            100        50         60
             India            200        50         50

  This is what I have tried 

     df3 = final_df2.pivot_table('country', 'fruits')
         

CodePudding user response:

You can try 'Piviot'

print(df.pivot(index='country', columns='Fruit grown', values='grown'))
  • Related