title: How to add rows in one column based on repeated values in another column , and finally keep the first row in python?
body: <p>I am very new to the python pandas module.</p>
  <p>Suppose I have a data frame or table as follows:</p>
  <pre><code> df = pd.DataFrame({
          'Column A': [12,12,12, 15, 16, 141, 141, 141, 141],
           'Column B':['Apple' ,'Apple' ,'Apple' , 'Red', 'Blue', 'Yellow', 'Yellow', 'Yellow', 'Yellow'],
          'Column C':[100, 50, np.nan , 23 , np.nan , 199 , np.nan , 1,np.nan]
      }) 
  </code></pre>
  <p>or I have a data table as follows:</p>
  <pre><code>
      | Column A | Column B |Column C 
  ----| -------- | ---------|--------
  0   | 12       | Apple    |100     
  1   | 12       | Apple    |50      
  2   | 12       | Apple    |NaN      
  3   | 15       | Red      |23       
  4   | 16       | Blue     |NaN      
  5   | 141      | Yellow   |199      
  6   | 141      | Yellow   |NaN      
  7   | 141      | Yellow   |1        
  8   | 141      | Yellow   |NaN  
  
  
  </code></pre>
  <ul>
  <li><p>If values in column A are repeated then add the corresponding values in Column C and paste the sum in new column D (For example, there are 3 rows for 12, thus we should add corresponding values 100 + 50 + NaN, and the sum result 150 should be stored in new column D).</p>
  </li>
  <li><p>If values in column A do not repeat directly paste Column C values in new column D (such as row 3) but for NaN, it should be 0 (such as row 4).</p>
  </li>
  </ul>
  <p>Could you please help me to get an output like this in python jupyter notebook:</p>
  <pre><code>      | Column A | Column B |Column C |Column D 
  ----- | -------- | ---------|---------|---------
   0    | 12       | Apple    |100      |150      
   1    | 15       | Red      |23       |23       
   2    | 16       | Blue     |NaN      |0        
   3    | 141      | Yellow   |199      |200  
  
  </code></pre>