<p>我有一个有两个国家描述的数据框。有时它们匹配,有时不匹配</p>
<pre><code>Country Desc1 Country Desc2
1 US US
2 US UK
3 UK US
4 UK UK
</code></pre>
<p>我需要1.)插入另一列(Country Desc3),其中所有行值都填充了2。)如果与Country Desc2匹配,则返回Country Desc1的规则。在</p>
<pre><code>df['Country Desc3'] = \
df['Country Desc1'].mask(df['Country Desc1'] != df['Country Desc2'])
df
Country Desc1 Country Desc2 Country Desc3
0 US US US
1 US UK NaN
2 UK US NaN
3 UK UK UK
</code></pre>