How to process column names and create new columns
<p>This is my pandas <code>DataFrame</code> with original column names.</p>

<pre><code>old_dt_cm1_tt   old_dm_cm1   old_rr_cm2_epf   old_gt
1               3            0                0
2               1            1                5
</code></pre>

<ol>
<li>Firstly I want to extract all unique variations of <code>cm</code>, e.g. in this case <code>cm1</code> and <code>cm2</code>.</li>
<li>After this I want to create a new column per each unique <code>cm</code>. In this example there should be 2 new columns.</li>
<li>Finally in each new column I should store the total count of non-zero original column values, i.e.</li>
</ol>

<blockquote>
<pre><code>old_dt_cm1_tt   old_dm_cm1   old_rr_cm2_epf   old_gt    cm1    cm2    
1               3            0                0         2      0        
2               1            1                5         2      1
</code></pre>
</blockquote>

<p>I implemented the first step as follows:</p>

<pre><code>cols = pd.DataFrame(list(df.columns))
ind = [c for c in df.columns if 'cm' in c]
df.ix[:, ind].columns
</code></pre>

<p>How to proceed with steps 2 and 3, so that the solution is automatic (I don't want to manually define column names <code>cm1</code> and <code>cm2</code>, because in original data set I might have many <code>cm</code> variations.</p>