pandas string to numeric
<p>I have a set of data like</p>

<pre><code>        a      b
0  type 1   True
1  type 2  False
</code></pre>

<p>How can I keep the numerical part of column <code>a</code> and transfer ture to 1, false to zero at the same time. Below is what I want.</p>

<pre><code>   a  b
0  1  1
1  2  0
</code></pre>

<p>You can convert Booleans to integers as follows:</p>

<pre><code>df['b'] = df.b.astype(int)
</code></pre>

<p>Depending on the nature of your text in Column <code>A</code>, you can do a few things:</p>

<p>a) Split on the space and take the second part (either string or int depending on your needs).</p>

<pre><code>df['a'] = df.a.str.split().str[1]  # Optional `.astype(int)`
</code></pre>

<p>b)  Use regex to extract any digits (<code>\d*</code>) from the end of the string.</p>

<pre><code>df['a'] = df.a.str.extract(r'(\d*)$')  # Optional `.astype(int)`
</code></pre>

python pandas numeric