title: Pandas - merge all all columns with the same substring
body: <p>I have many columns that contain the same substring and i want to merge them to one using OR function.</p>
  
  <p>So i want to merge all columns that have the same</p>
  
  <pre><code>dfin.columns.str.split("_").str[1]
  
  first_RG7509|   first_YY6124|   last_YY6124|    first_WE4818|first_AA7542|  last_RG7509
  
  1|0|1|1|0|0
  </code></pre>
  
  <p>and the output should be:</p>
  
  <pre><code>RG7509|YY6124|WE4818|AA7542
  
  1|1|1|0
  </code></pre>
  
  <p>How can I achieve this?</p>