擅长:python、mysql、java
<p>您可以将new <code>Series</code>与<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow noreferrer">^{<cd2>}</a>一起使用,这将为不存在的<code>Nation</code>s<code>NaN</code>s创建,它们将替换为<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.fillna.html" rel="nofollow noreferrer">^{<cd5>}</a>:</p>
<pre><code>s = df2.set_index('Nation')['Capital City']
df1['Capital'] = df1['Country'].map(s).fillna(df1['Capital'])
print (df1)
No Country Language Capital
0 1 Indonesia Bahasa Jakarta
1 2 Malaysia Bahasa Lagos
2 3 Brunei Bahasa Bandar Seri Begawan
3 4 Nigeria English Putrajaya
</code></pre>
<p>或带有<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.replace.html" rel="nofollow noreferrer">^{<cd6>}</a>的慢溶液:</p>
^{pr2}$