text: Q:
  
  Python dataframe apply function groupby and per column
  
  I have a dataframe:
  df = Condition A_value B_value
         15       2       3
         30       1       8
         45       5       1
         15       3       9
         30       4       6
         45       8       2
         15       5       2
         30       7       3
         45       9       1
         15       0       8
         30       8       7
         45       1       3
  
  I want to apply sklearn.preprocessing.StandardScaler
  On each column , by the type. (meaning it will scale the column A_value for rows where condition=15, then A_value for 30, 45 , and B_value for  15, then 30, then 45.
  Is there a way to do it without iterating over all groups? (e.g one-liner?)
  What is the best way to do it?
  
  A:
  
  Use GroupBy.transform for processing each column per groups separately with Series.to_frame, DataFrame.set_index is added for processing all columns without Condition:
  from sklearn.preprocessing import StandardScaler
  
  f = lambda x: (StandardScaler().fit_transform(x.to_frame()))[:, 0]
  df = df.set_index('Condition').groupby('Condition').transform(f).reset_index()
  print (df)
      Condition   A_value   B_value
  0          15 -0.277350 -0.821995
  1          30 -1.460593  1.069045
  2          45 -0.240966 -0.904534
  3          15  0.277350  1.150793
  4          30 -0.365148  0.000000
  5          45  0.722897  0.301511
  6          15  1.386750 -1.150793
  7          30  0.730297 -1.603567
  8          45  1.044185 -0.904534
  9          15 -1.386750  0.821995
  10         30  1.095445  0.534522
  11         45 -1.526117  1.507557
  
  