title: Creating new column in pandas dataframe with a list of values from another column without using "groupby"
body: <p>I work with large datasets, making pandas group and groupby functions take a long time/use too much memory. I have heard some people say groupby can be slow, but am having trouble finding a better solution. </p>
  
  <p>If my dataframe has 2 columns similar to:</p>
  
  <pre><code>df = pd.DataFrame({'a':[1,2,2,4], 'b':[1,1,1,1]})
  
  a     b     
  1     1     
  2     1     
  2     1      
  4     1     
  </code></pre>
  
  <p>I wish to return a list of values that match to a value in another column:</p>
  
  <pre><code>a     b     list_of_b
  1     1        [1]
  2     1        [1,1]
  2     1        [1,1]
  4     1        [1]
  </code></pre>
  
  <p>I currently use:</p>
  
  <pre><code>df_group = df.groupby('a')
  df['list_of_b'] = df.apply(lambda row: df_group.get_group(row['a'])['b'].tolist(), axis=1)
  </code></pre>
  
  <p>The code above works for small stuff, but not on large dataframes ( df > 1,000,000 rows) Does anyone have a faster way to do this?</p>