Convert pandas python data frame column values in place
<p>I have a column of positive and negative numbers and I want to convert it to a list of 0s and 1s. If the number if positive, it should be replaced with a 1. If the number is negative or 0, it should be replaced by a 0. How can I do this?</p>

<p>For example, in R, I would do:</p>

<pre><code>list = ifelse(list &gt; 0, 1, 0)
</code></pre>

<p>You can return <code>boolean</code> values and use <code>astype(int)</code> to convert them to <code>1</code> and <code>0</code>. </p>

<pre><code>print((df['A'] &gt; 0).astype(int))
</code></pre>

<p><strong>Example:</strong>   </p>

<pre><code>df = pd.DataFrame({'A': [1,-1,2,-2,3,-3]})
print(df)
A
0  1
1 -1
2  2
3 -2
4  3
5 -3
print((df['A'] &gt; 0).astype(int))
0    1
1    0
2    1
3    0
4    1
5    0
</code></pre>

python pandas dataframe