title: Efficient way to create a new column that is the sum of unique values grouped by another column?
body: <p>I have a dataframe which has a name and size column. I need to create a new column (size_total) that is the total of all unique size values grouped by the name column.</p>
  
  <pre class="lang-py prettyprint-override"><code>df = pd.DataFrame([     
      {'sp': 'A', 'size': 25},     
      {'sp': 'B', 'size': 26},     
      {'sp': 'C', 'size': 27},     
      {'sp': 'A', 'size': 25},     
      {'sp': 'B', 'size': 42},     
      {'sp': 'C', 'size': 27},     
      {'sp': 'A', 'size': 25},     
      {'sp': 'B', 'size': 32},     
      {'sp': 'C', 'size': 33}])
  
  df['size_total'] = df['sp'].map(df[['sp', 'size']].drop_duplicates(keep='first').groupby('sp').sum()['size'])
  </code></pre>
  
  <p>Is there a more efficient way to do this?</p>