pandas keep numerical part
<p>I have a set of data like: </p>

<pre><code>        0       1 
0  type 1  type 2
1  type 3  type 4
</code></pre>

<p>How can I transfer it to:</p>

<pre><code>   0  1
0  1  2
1  3  4
</code></pre>

<p>perfer using <code>apply</code>or <code>transform</code> function</p>

<p><strong><em>Option 1</em></strong></p>

<pre><code>df.stack().str.replace('type ', '').unstack()
</code></pre>

<p><strong><em>Option 2</em></strong></p>

<pre><code>df.stack().str.split().str[-1].unstack()
</code></pre>

<p><strong><em>Option 3</em></strong></p>

<pre><code># pandas version 0.18.1 +
df.stack().str.extract('(\d+)', expand=False).unstack()

# pandas version 0.18.0 or prior
df.stack().str.extract('(\d+)').unstack()
</code></pre>

<p><a href="http://i.stack.imgur.com/u1NLv.png" rel="nofollow"><img src="http://i.stack.imgur.com/u1NLv.png" alt="enter image description here"></a></p>

<hr>

<h3>Timing</h3>

<p><strong><em>conclusion</em></strong> @jezreal's is best.  no loops and no stacking.</p>

<p><strong><em>code</em></strong></p>

<p><strong><em>20,000 by 200</em></strong></p>

<pre><code>df_ = df.copy()

df = pd.concat([df_ for _ in range(10000)], ignore_index=True)
df = pd.concat([df for _ in range(100)], axis=1, ignore_index=True)
</code></pre>

<p><a href="http://i.stack.imgur.com/e6v6G.png" rel="nofollow"><img src="http://i.stack.imgur.com/e6v6G.png" alt="enter image description here"></a></p>

python string pandas replace numeric