For some background, I've been trying to take the average of a dataset for each fiscal week for each unique name in the dataset as well. I start with the dataset that looks something like this:
pad | fiscal_week | value |
---|---|---|
Verace | 5 | 23 |
Jersey | 5 | 20 |
Verace | 5 | 20 |
Verace | 5 | 22 |
Verace | 6 | 30 |
Colorado | 4 | 15 |
What I currently have:
unique_week = df['fiscal_week'].unique()
unique_week = sorted(unique_week)
newCols = pd.DataFrame()
for week_number in unique_week:
unique_id = df['pad'].unique()
turbine_reg = df[df['fiscal_week'] == week_number]
newColname = 'FW' + str(week_number)
for turbine_name in unique_id:
turbine_name_reg = turbine_reg[turbine_reg['pad'] == turbine_name]
value_mean = [turbine_name_reg['value'].mean()]
newCols['Turbine'] = turbine_name
newCols[newColname] = direct_mean
What I would like, is for the end product to look something like:
pad | FW1 | FW2 | FW3 |
---|---|---|---|
Verace | 22 | 23 | 24 |
Jersey | 15 | 16 | 20 |
Colorado | 23 | 25 | 16 |
Currently, I'm only getting the result for the last unique pad the loop run on and not saving the times it runs for the other pads. I know the loop is overwriting itself each time, but I'm not sure how to fix it.
Any ideas?