title: Populate df column on median of a subset from another df
body: <p>I have two dataframes: one representing blocks of samples (df1) and another that has performance values for multiple samples in a time series (df2). I would like to populate df1 by slicing df2 using a dictionary and calculating the median. While I could brute force it through a for loop, I would like to learn the more appropriate approach. I feel like df.apply() should be able to do it, but I run into a &quot;'Series' objects are mutable, thus they cannot be hashed&quot; error.</p>
  <pre><code>df1=pd.DataFrame(columns=['qb','qb_median'])
  df1.qb=['qb1','qb2']
  
  df1
  Out[76]: 
      qb qb_median
  0  qb1       NaN
  1  qb2       NaN
  
  df2=pd.DataFrame({'sample':['A','B','C','D','E','F'],'x':[1,2,3,4,5,6]})
  
  df2
  Out[78]: 
    sample  x
  0      A  1
  1      B  2
  2      C  3
  3      D  4
  4      E  5
  5      F  6
  
  sets={'qb1':['A','B','C'],'qb2':['D','E','F']}
  </code></pre>
  <p>I would like to populate df1 such that</p>
  <pre><code>    qb qb_median
  0  qb1       2
  1  qb2       5
  </code></pre>
  <p>What I thought might work was something like:</p>
  <pre><code>def get_med(q, lookup_df):
       return lookup_df.loc[lookup_df['sample'].isin(sets[q])]['x'].median()
  
  df1['qb_median']=df1.apply(lambda x: get_med(df1.qb, df2), axis=1)
  </code></pre>
  <p>I've also tried variations of:</p>
  <pre><code>df1['qb_median']=df2.loc[df2['sample'].isin(sets[df1.qb_median])]['x'].median()
  </code></pre>
  <p>I feel like I'm 'right there', but just can't make it work. Any help would be appreciated.</p>