Skip to content Skip to sidebar Skip to footer

Pandas Scale Multiple Columns At Once And Inverse Transform With Groupby()

I have a dataframe like below.I want to apply two MinMaxscalers on x_data ad y_data on multiple columns and then inverse transform should give me the actual values.Please suggest

Solution 1:

The MinMaxScalar can accept multi pandas numeric serieses at once, and scales them column-wise, so you can simply do:

x_scaler = MinMaxScaler()
scaled_xdata = x_scaler.fit_transform(df.iloc[:, 1:])
scaled_xdata_inv = x_scaler.inverse_transform(scaled_xdata)

No need for groupbys or lambdas


Post a Comment for "Pandas Scale Multiple Columns At Once And Inverse Transform With Groupby()"