'split single df column into multiple columns based on value (python) [duplicate]

I'm new to python, an am working on support scripts to help me import data from various sources. within the df are several years of daily values. I would like to split & sort the daily_cfs column into multiple separate columns based on the water_year value. Would this require groupby or would a pivot table be better?

in short I want to turn df:

original df

into another df resembling this:

excel file resembled finished df



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source