1

I have a dataFrameGroupBy object with several columns, on of them is 'price'.

Since each group has a different price range, I would like to normalize each group separately.

following this question I tried :

grouped['priceNormed'] = grouped['price'].transform(lambda x: (x-x.mean()) / x.std())

but I get an error TypeError: 'DataFrameGroupBy' object does not support item assignment

The difference is (I think) that I am grouping by one column, but want to normalize another.

ArieAI
  • 354
  • 1
  • 12

1 Answers1

3

You should assign back to the DataFrame, not GroupBy object:

grouped = df.groupby(...)
df['priceNormed'] = grouped['price'].transform(lambda x: (x-x.mean()) / x.std())
mozway
  • 194,879
  • 13
  • 39
  • 75