I have a below table and want to calculate mean by state, I would like to calculate mean only for the rows which has 1 as customer
| Customer | State | Score | Output_Mean |
|---|---|---|---|
| 0 | GA | 1 | |
| 1 | GA | 2 | 2.5 |
| 1 | GA | 3 | 2.5 |
| 1 | NY | 9 | 8 |
| 1 | NY | 7 | 8 |
| 0 | DC | 6 | |
| 0 | DC | 4 |
I have below code, how do I add customer criteria?
df['output_mean'] = (df.fillna({'state':'missing'}).groupby(['state'])['score'].transform(lambda x: x.mean()))