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 following worked for me</p>

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

python pandas