Convert a str typed series to numeric where I can
<p>Consider the str type series <code>s</code></p>

<pre><code>s = pd.Series(['a', '1'])
</code></pre>

<hr>

<pre><code>pd.to_numeric(s, 'ignore')

0    a
1    1
dtype: object
</code></pre>

<hr>

<pre><code>pd.to_numeric(s, 'ignore').apply(type)

0    &lt;type 'str'&gt;
1    &lt;type 'str'&gt;
dtype: object
</code></pre>

<p>Clearly, both types are still string.  It seems that the <code>'ignore'</code> option ignores the entires series conversion.  How do I get it to do what it can and ignore the rest.</p>

<p>I want the series types to be</p>

<pre><code>pd.to_numeric(s, 'ignore').apply(type)

0    &lt;type 'str'&gt;
1    &lt;type 'int'&gt;
dtype: object
</code></pre>

<hr>

<p>EDIT: I came up with this after I posted the question and after @ayhan provided an answer.</p>

<p><strong><em>My solution</em></strong><br>
Not vectorized, but gives me exactly what I want</p>

<pre><code>s.apply(pd.to_numeric, errors='ignore')
</code></pre>

<p>This is what I am using:</p>

<pre><code>pd.to_numeric(s, errors='coerce').fillna(s)
Out: 
0    a
1    1
dtype: object
</code></pre>

<hr>

<pre><code>pd.to_numeric(s, errors='coerce').fillna(s).apply(type)
Out: 
0      &lt;class 'str'&gt;
1    &lt;class 'float'&gt;
dtype: object
</code></pre>

python pandas