count the number of groups of consecutive digits in a series of strings
<p>consider the <code>pd.Series</code> <code>s</code></p>

<pre><code>import pandas as pd
import numpy as np

np.random.seed([3,1415])
p = (.35, .35, .1, .1, .1)
s = pd.DataFrame(np.random.choice(['', 1] + list('abc'), (10, 20), p=p)).sum(1)

s

0    11111bbaacbbca1
1    1bab111aaaaca1a
2    11aaa1b11a11a11
3     1ca11bb1b1a1b1
4        bb1111b1111
5       b1111c1aa111
6     1b1a111b11b1ab
7        1bc111ab1ba
8      a11b1b1b11111
9        1cc1ab1acc1
dtype: object
</code></pre>

<hr>

<p>I'm looking to count the number of groups of consecutive digits in each element of <code>s</code>.  Or, how many integers are in each string.</p>

<p>I'd expec the result to look like</p>

<pre><code>0    2
1    3
2    5
3    6
4    2
5    3
6    5
7    3
8    4
9    4
dtype: int64
</code></pre>

<p>I'm looking for efficiency, though elegance is important too.</p>

<p>This was my solution</p>

<pre><code>s.str.replace(r'\D+', ' ').str.strip().str.split().str.len()
</code></pre>

<p><strong><em>100,000 rows</em></strong></p>

<pre><code>np.random.seed([3,1415])
p = (.35, .35, .1, .1, .1)
s = pd.DataFrame(np.random.choice(['', 1] + list('abc'), (100000, 20), p=p)).sum(1)
</code></pre>

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

python pandas