I'm trying to apply scaler to columns of a dataframe after groupby.
scaler = MinMaxScaler()
df = pd.DataFrame({'a':[1,2,3,4,5,], 'b':[10,20,30,40,50,], 'k':[False, True, False, True, False]})
for name, g in df.groupby('k'):
scaler = MinMaxScaler()
scaler.fit(g['a'].values[..., np.newaxis])
for col in ['a', 'b']:
new_v = scaler.transform(g[col].values[..., np.newaxis])[:, 0]
print(new_v)
g[col] = new_v
How to make the operation actually change the df
itself?