I have sales dataset as below: df1
district item Year salesAmount
Arba pen 2019 10
Arba pen 2019 20
Arba pencil 2018 30
Arba pencil 2018 30
Arba pencil 2019 30
Cebu pen 2019 100
Cebu pen 2019 300
Cebu pen 2018 100
Cebu pen 2018 100
Cebu pen 2019 100
Cebu laptop 2019 20000
Cebu laptop 2018 20000
Cebu fruit 2019 200
Cebu fruit 2018 800
Cebu fruit 2019 800
Cebu fruit 2018 100
I could complete groupby and get the aggregated sum for each prodcut for 2018 and 2019 respectively.
result = df1.groupby(['district', 'item', 'Year'], as_index=False)['salesAmount'].sum()
But I want to have to a tabular column as below inroder to do further transofrmation of columns
Expected output:
district item 2018_sales 2019_sales
Arba pen 0 30
Arba pencil 60 30
Cebu pen 500 200
Cebu laptop 20000 20000
Cebu fuit 900 1000
Thanks.