Applying condition and update on same column
<p>I have written the following statement to update a column in DataFrame (df)</p>

<pre><code>    score
0   6800
1   7200
2   580
3   6730
</code></pre>

<p>df["score"] = (df["score"]/10).where(df["score"] > 999)</p>

<p>The idea is to clean up the score column to remove the extra '0' at the end, only if the number is greater than 999 else keep unchanged. However, i get the following result.</p>

<pre><code>0    680.0
1    720.0
2      NaN
3    673.0
</code></pre>

<p>Also, I want the result as Integers.</p>

<p>my expected output</p>

<pre><code>0    680
1    720
2    580
3    673
</code></pre>

<p><strong>Update</strong></p>

<p>the following worked for me</p>

<pre><code>df["score"] = np.where(df["score"] &gt; 999, df["score"]/10, df["score"]).astype(int)
</code></pre>

<p>The value for index 2 will not satisfy your filter condition (i.e. <code>&gt; 999</code>) and will yield a <code>NaN</code>, as per the <a href="http://pandas.pydata.org/pandas-docs/stable/dsintro.html#series" rel="nofollow">documentation</a>:</p>

<blockquote>
  <p>Note: <code>NaN</code> (not a number) is the standard missing data marker used in pandas </p>
</blockquote>

python pandas