<p>将<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.map.html" rel="nofollow noreferrer">^{<cd1>}</a>与<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.set_index.html" rel="nofollow noreferrer">^{<cd3>}</a>创建的<code>Series</code>一起使用,然后使用<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.fillna.html" rel="nofollow noreferrer">^{<cd4>}</a>:</p>
<pre><code>s = df.set_index(['source'])['target']
#if possible duplicates in source
#s = df.drop_duplicates('source').set_index(['source'])['target']
df['new_target'] = df['target'].map(s).fillna(df['target'])
print (df)
source target new_target
0 jan feb aug
1 mar apr jul
2 jun
3 feb aug nov
4 apr jul jul
5 oct dec may
6 aug nov nov
7 dec may may
</code></pre>
<p>编辑:</p>
<pre><code>s = df.set_index(['source'])['target']
#if possible duplicates in source
#s = df.drop_duplicates('source').set_index(['source'])['target']
df['new_target'] = df['target'].map(s)
print (df)
source target new_target
0 jan feb aug
1 mar apr jul
2 jun NaN
3 feb aug nov
4 apr jul NaN
5 oct dec may
6 aug nov NaN
7 dec may NaN
</code></pre>