Pandas groupby in combination with sklean preprocessing continued
问题 Continue from this post: Pandas groupby in combination with sklearn preprocessing I need to do preprocessing by scaling grouped data by two columns, somehow get some error for the second method import pandas as pd import numpy as np from sklearn.preprocessing import robust_scale,minmax_scale df = pd.DataFrame( dict( id=list('AAAAABBBBB'), loc = (10,20,10,20,10,20,10,20,10,20), value=(0,10,10,20,100,100,200,30,40,100))) df['new'] = df.groupby(['id','loc']).value.transform(lambda x:minmax_scale