擅长:python、mysql、java
<p>您可以使用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.contains.html" rel="nofollow noreferrer">str.contains</a>+<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow noreferrer">numpy.where</a>:</p>
<pre><code>df['MinP'] = np.where(df.MaxP.str.contains('+/-', regex=False), df.MaxP, df.MinP)
print(df)
</code></pre>
<p><strong>输出</strong></p>
<pre><code> MinP MaxP
0 0 20
1 15
2 -10 12
3 +/-20 +/-20
</code></pre>
<p>注意,您必须使用<code>regex=False</code>,以避免将模式解释为正则表达式</p>