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 use an indexer and .loc to change values such has</p>

<pre><code> indexer = df[df['col']&gt;0].index
 df.loc[indexer] = 1

  indexer_2 = df[df['col']&lt;0].index
  df.loc[indexer_2] = 0
</code></pre>

<p>or you can look at numpy.where such has</p>

<pre><code>import numpy as np
import pandas as pd
pd.DataFrame(np.where(df&gt;0,1,0),index=df.index)
</code></pre>

python pandas dataframe