I have a dataset(code below)- that looks like below -
d = pd.DataFrame({
'Year': [
2019,
2020,
2021,
2022,
2019,
2020,
2020,
2021,
2019,
2020,
2021,
2022
],
'Category': [
'Salary',
'Salary',
'Salary',
'Salary',
'Misc',
'Misc',
'Misc',
'Misc',
'Bonus',
'Bonus',
'Bonus',
'Bonus',
],
'Amount': [
53,
455,
123,
125,
313,
545,
595,
775,
567,
657,
567,
547
]
})
I want to transform it to something like below -
Is there a pythonic way to achieve this - apart from getting unique 'Category', transposing it and then looping over Amount column to find the corresponding amount? It is not a exact transpose or group by but something similar to that.