title: Groupby and A)Concate matching strings(and or substring) B)Sum the values
body: <p><strong>I have df:</strong></p>
  
  <pre><code>row_numbers    ID     code        amount
     1           med    a           1
     2           med    a, b        1
     3           med    b, c        1
     4           med    c           1
     5           med    d           10
     6           cad    a, b        1 
     7           cad    a, b, d     0
     8           cad    e           2
  </code></pre>
  
  <p>Pasted the above df:</p>
  
  <p><a href="https://i.stack.imgur.com/tFrWG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tFrWG.png" alt="enter image description here"></a></p>
  
  <p>I wanted to do groupby on column-<strong>ID</strong> and A)Combine the strings if substring/string matches(on column-<strong>code</strong>) B)sum the values of column-<strong>amount</strong>.</p>
  
  <p><strong>Expected results:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/sSSAu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sSSAu.png" alt="enter image description here"></a></p>
  
  <p><strong>Explanation:</strong></p>
  
  <p>column-<strong>row_numbers</strong> has no role here in df. I just took here to explain the output. </p>
  
  <p>A)grouping on column-<strong>ID</strong> and looking at column-<strong>code</strong>, row1 string i.e., a is matching with row2's sub string. row2's substring i.e., b is matching with row3's substring. row3's substring i.e., c is matching with string of row4 and Hence combining row1, row2, row3 and row4. row5 string is not matching with any of string/substring so it is separate group. B) Based on this adding row1, row2, row3 and row4 values. and row5 as separate group. </p>
  
  <p>Thanks in advance for your time and thoughts:).</p>
  
  <p><strong>EDIT - 1</strong></p>
  
  <p>Pasting the real time.</p>
  
  <p><a href="https://i.stack.imgur.com/ZvkAu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZvkAu.png" alt="enter image description here"></a></p>
  
  <p><strong>Expected output:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/C3V2N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C3V2N.png" alt="enter image description here"></a></p>
  
  <p><strong>Explanation:</strong></p>
  
  <p>have to do on grouping column-<strong>id</strong> and concatenating the values of column-<strong>code</strong> and summing the values of column-<strong>units</strong> and <strong>vol</strong>. It is color coded the matching(to be contacted) values of column-<strong>code</strong>. row1 has link with row5 and row9. row9 has inturn link with row3. Hence combining row1, row5, row9, row3. Simliarly row2 and row7 and so on. row8 has no link with any of the values with-in group-med(column-id) and hence will be as separate row.</p>
  
  <p>Thanks!.</p>