擅长:python、mysql、java
<p>使用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.where.html" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>df['Termination_Date'] = df['Effective Date'].where( (df['Cancellations'] == 'Yes') |
(df['Lapses'] == 'Yes') )
</code></pre>
<p>或<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.mask.html" rel="nofollow noreferrer">^{<cd2>}</a></p>
<pre><code>df['Termination_Date'] = df['Effective Date'].mask( df['Cancellations'].ne('yes')
.mul(df['Lapses'].ne('Yes') )
</code></pre>
<hr/>
<p>我们也可以用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.any.html" rel="nofollow noreferrer">^{<cd3>}</a>检查</p>
<pre><code>df['Termination_Date'] = df['Effective Date'].where( df[['Lapses','Cancellations']].eq('Yes').any(axis = 1) )
</code></pre>