3

I have a dataframe that looks like this (dfFF):

    Sector  Country    Currency    Amount    Year
0   Charity    UK         GBP      328163    2018
1   Public     UK         GBP      120480    2017
2   Public     UK         GBP      123086    2017
3   Public     UK         GBP      125198    2017
4   Public     UK         GBP      1502793   2017
5   Public     UK         GBP      249999    2016

And I want to pivot it so I have Country as the rows and Sector on the columns with the Amount summed.

I use the code:

dfFFB = pd.pivot_table(dfFF, index=['Country'], columns=['Sector'], aggfunc='sum', fill_value=0)

And I get this:

    Year
Sector     Charity     Public
Country     
   UK       4036       28234

Which is summing the year, not the amount.

How would I force it to sum the Amount?

Nicholas
  • 3,517
  • 13
  • 47
  • 86

0 Answers0