<p>用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.clip_lower.html" rel="nofollow noreferrer">^{<cd1>}</a>和
<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.clip_upper.html" rel="nofollow noreferrer">^{<cd2>}</a>,也<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.mul.html" rel="nofollow noreferrer">^{<cd3>}</a>用于乘以<code>-1</code>:</p>
<pre><code>sls_item['SALES'] = sls_item['T$QOOR'].clip_lower(0)
sls_item['RETURN'] = sls_item['T$QOOR'].clip_upper(0).mul(-1)
print (sls_item)
T$QOOR SALES RETURN
0 3 3 0
1 14 14 0
2 12 12 0
3 -6 0 6
4 -19 0 19
5 9 9 0
</code></pre>
<p>使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.where.html" rel="nofollow noreferrer">^{<cd5>}</a>或<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow noreferrer">^{<cd6>}</a>:</p>
<pre><code>sls_item['SALES'] = sls_item['T$QOOR'].where(lambda x: x >= 0, 0)
sls_item['RETURN'] = sls_item['T$QOOR'].where(lambda x: x < 0, 0) * -1
print (sls_item)
T$QOOR SALES RETURN
0 3 3 0
1 14 14 0
2 12 12 0
3 -6 0 6
4 -19 0 19
5 9 9 0
</code></pre>
<hr/>
<pre><code>mask = sls_item['T$QOOR'] >=0
sls_item['SALES'] = np.where(mask, sls_item['T$QOOR'], 0)
sls_item['RETURN'] = np.where(~mask, sls_item['T$QOOR'] * -1, 0)
print (sls_item)
T$QOOR SALES RETURN
0 3 3 0
1 14 14 0
2 12 12 0
3 -6 0 6
4 -19 0 19
5 9 9 0
</code></pre>