title: Apply median from a subset to entire column, Python /Pandas
body: <p>first time posting here.
  I have a credit risk model data set that has 38K accounts. 25K accounts are training data. The other 13K are OOT (out of time validation). All the 200 columns have the same definitions between training and OOT. Just the data has two parts.</p>
  <p>I need to impute missing data. 37 columns of the 200 are qualified for median imputation. Here is my code that works fine. (Due to company confidentiality, I use general variable names)</p>
  <pre><code>Interval37 =whole[['interval1','interval2'....'interval37']].apply(pd.to_numeric,errors='coerce')
  Interval37=interval37.fillna(Interval37.median())
  </code></pre>
  <p>I must modify this because training is not supposed to see the OOT portion during training, even if it is just calculating median. So I tried the code below</p>
  <pre><code>Traindata=whole.query('partx==1')  #partx== 1 indicates this is the 25K training accounts
  Train37 =Traindata[['interval1', 'interval2'...'interval37']].apply(pd.to_numeric,errors='coerce')
  trainmedian=Train37.median()
  whole=whole(trainmedian)  #Whole is the entire 37K accounts
  </code></pre>
  <p>This code runs with no error. Just it is not imputing. Same data in, same data out. I read several posts that apply subset median individually to each subset using groupby. My problem is the opposite. I need to spread median from a subset to the entire data frame. Or I need to apply, transform the entire data using median from the training data. Please help. Jia</p>