There is a dataframe like this
df
| group | data | other |
|---|---|---|
| A | 1 | a |
| A | 2 | b |
| A | 3 | ad |
| A | 4 | aw |
| A | 5 | ad |
| B | 100 | ta |
| B | 200 | as |
| B | 300 | ab |
| B | 400 | ax |
| B | 500 | ad |
I would like to groupby("group") then apply standard_scaler().fit_transform() in each group
( I test with only data with a single group in data from with this code which is working but I having problem when group data >1
df['data'] = pd.DataFrame(scaler.fit_transform(df.groupby('group').data.values.reshape(-1,1)))
)
I was wondering is there a way to solve this with multiple group and apply scaler in each group?
Edited: My Desire output would be
| group | data | other |
|---|---|---|
| A | -1.414 | a |
| A | -0.7071 | b |
| A | 0 | ad |
| A | 0.7071 | aw |
| A | 1.414 | ad |
| B | -1.414 | ta |
| B | -0.7071 | as |
| B | 0 | ab |
| B | 0.7071 | ax |
| B | 1.414 | ad |
where data is transform data of normalized data