The problem I am having is if I have the following dataframe that has been sorted by the Customer Number and Date columns, how do get the dates for each customer and corresponding salaries into new columns one by one.
df = pd.DataFrame({'Customer Number':[1,1,1,2,2,3,3,3],
'Date': [2013, 2014, 2015, 2016, 2017, 2013, 2014, 2015],
'Salaries': [100, 200, 200, 300, 300, 4000, 5000, 5000]})
produces:
Customer Number Date Salaries
0 1 2013 100
1 1 2014 200
2 1 2015 200
3 2 2016 300
4 2 2017 300
5 3 2013 4000
6 3 2014 5000
7 3 2015 5000
For this problem, the output I am trying to obtain is something like the following:
Customer Number Date 1 Salary 1 Date 2 Salary 2 Date 3 Salary 3
0 1 2013 100 2014 200 2015 200
1 2 2016 300 2017 300 NaN NaN
2 3 2013 4000 2014 5000 2015 5000
I have tried using pivot tables to arrange this data and numpy for reshaping the table but can't quite manage to get the new columns for dates and salaries in this way. I was hoping there would be a nice and simple solution to this but couldn't manage to find it. I'd really appreciate any help with this problem.