Convert string column to integer
<p>I have a dataframe like below</p>

<pre><code>    a   b
0   1   26190
1   5   python
2   5   580
</code></pre>

<p>I want to make column <code>b</code> to host only integers, but as you can see <code>python</code> is not int convertible, so I want to delete the row at index <code>1</code>. My expected out put has to be like</p>

<pre><code>    a   b
0   1   26190
1   5   580
</code></pre>

<p>How to filter and remove using pandas in python?</p>

<p>This should work</p>

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

df = pd.DataFrame({'a' : [1, 5, 5],
                   'b' : [26190, 'python', 580]})
df
   a       b
0  1   26190
1  5  python
2  5     580

df['b'] = np.where(df.b.str.contains('[a-z]') == True, np.NaN, df.b)
df
   a      b
0  1  26190
1  5    NaN
2  5    580

df = df.dropna()
df
   a      b
0  1  26190
2  5    580
</code></pre>

<p>You use the regex to identify strings, then convert these to <code>np.NaN</code> using <code>np.where</code> then drop them from the df with <code>df.dropna()</code>. </p>

python string pandas numpy int