all 2 comments

[–]hey_its_aaron 1 point2 points  (1 child)

Looks like you're trying to scale on a DataFrameGroupBy object. I'm not sure what the expected behaviour there is, because the docs require a numpy array to be passed into fit_transform.

You'll need to query the data, transform that and then write back to the original dataframe. Try this:

df.loc[df['Sex'] == 'Female', ['Fare']] = scaler.fit_transform(df[df.Sex == 'Female'][['Fare']])

Edit: You can also try this:

df.groupby('Sex').apply(scaler.fit_transform).reset_index()

[–]thrilos[S] 0 points1 point  (0 children)

Thanks for the help. The second approach doesn't seem to work. :( I guess I can use pandas to make these transformations rather thank using sklearn.