title: Drop Duplicates and Add Values Pandas
body: <p>I have a dataframe below. I would like to drop the duplicates, but add the duplicated value from the <code>E</code> column to the non-duplicated record</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  dfp = pd.DataFrame({'A' : [np.NaN,np.NaN,3,4,5,5,3,1,6,7], 
                      'B' : [1,1,3,5,0,0,np.NaN,9,0,0], 
                      'C' : ['AA1233445','AA1233445', 'rmacy','Idaho Rx','Ab123455','TV192837','RX','Ohio Drugs','RX12345','USA Pharma'], 
                      'D' : [123456,123456,1234567,12345678,12345,12345,12345678,123456789,1234567,np.NaN],
                      'E' : ['Assign','Allign','Hello','Ugly','Appreciate','Undo','Testing','Unicycle','Pharma','Unicorn',]})
  print(dfp)
  </code></pre>
  
  <p>I'm grabbing all the duplicates:</p>
  
  <pre><code>df2 = dfp.loc[(dfp['A'].duplicated(keep=False))].copy()
  
       A    B          C           D           E
  0  NaN  1.0  AA1233445    123456.0      Assign
  1  NaN  1.0  AA1233445    123456.0      Allign
  2  3.0  3.0      rmacy   1234567.0       Hello
  4  5.0  0.0   Ab123455     12345.0  Appreciate
  5  5.0  0.0   TV192837     12345.0        Undo
  6  3.0  NaN         RX  12345678.0     Testing
  </code></pre>
  
  <p>and would like my outcome to be:</p>
  
  <pre><code>     A    B          C           D           E
  0  NaN  1.0  AA1233445    123456.0      Assign Allign
  2  3.0  3.0      rmacy   1234567.0      Hello Testing
  4  5.0  0.0   Ab123455     12345.0      Appreciate Undo
  </code></pre>
  
  <p>I know I need to use <code>dfp.loc[(dfp['A'].duplicated(keep='last'))].copy()</code> to grab the first occurrence, but I'm failing to set the value of the <code>E</code> column to include the other duplicated values.</p>
  
  <p>I'm thinking I need to try something like:  </p>
  
  <pre><code>df3 = dfp.loc[(dfp['A'].duplicated(keep='last'))].copy()
  df3['E'] = df3['E'] + dfp.loc[(dfp['A'].duplicated(keep=False).copy()),'E']
  </code></pre>
  
  <p>but my output is: </p>
  
  <pre><code>     A    B          C          D                     E
  0  NaN  1.0  AA1233445   123456.0          AssignAssign
  2  3.0  3.0      rmacy  1234567.0            HelloHello
  4  5.0  0.0   Ab123455    12345.0  AppreciateAppreciate
  </code></pre>
  
  <p>I'm stumped. Am I over complicating it? How can I get the output I'm looking for so that I can later drop all the duplicates, except the first, but 'save' the values of the dropped vlaues in the <code>E</code> Column?</p>