I am trying to unstack a column in python but it isn't quite doing what I am expecting. My table looks similar to this:
Station_id year month Day1 Day2
210018 1916 1 4 7
2 6 NaN
3 2 1
256700 1917 1 NaN 8
2 6 9
3 2 0
I want to unstack by month so that all the days from a months are in one row. The two days from month one would then start first followed by the 2 days from month two then the 2 days from month three and so on. I no longer need the month column after this and I have tried deleting it and unstacking but it won't work.
The table would look like this:
Station_id year
210018 1916 4 7 6 NaN 2 1
256700 1917 NaN 8 6 9 2 0
When I try df.unstack(2)
right now it returns a result that looks like this:
Station_id year
210018 1916 4 6 2 7 NaN 1
256700 1917 NaN 6 2 8 9 0
Any help would be much appreciated