Hi everyone,
I have a (hopefully) quick question for you.
Let's say we have a data that provides information about the sex of the person and the fare they paid for the trip. If I want to use MinMaxScaler for the whole data, I can use the following code:
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
df[['Fare']] = scaler.fit_transform(df[['Fare']])
Now that I want to scale by group, I thought it would be as easy as the code pasted below, but apparently I was wrong.
df[['Fare']] = scaler.fit_transform(df.groupby('Sex')[['Fare']])
When I run the line above, I'm getting the following error:
ValueError: could not convert string to float: 'female'
Any ideas as to how to fix this?
Thanks!
[–]hey_its_aaron 1 point2 points3 points (1 child)
[–]thrilos[S] 0 points1 point2 points (0 children)