<p>我认为您需要由<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow noreferrer">^{<cd3>}</a>创建的<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow noreferrer">^{<cd1>}</a>,如果某些值与get <code>NaN</code>不匹配:</p>
<pre><code>#change data for match
print (df1)
UniProtID NAME
0 O75015 PPP2R5B
1 P00734 PPP2R1B
2 P63151 PPP2R2A
df2['UniProt Name'] = df2['UniProtID'].map(df1.set_index('UniProtID')['NAME'])
print (df2)
DrugBankID Name Type UniProtID UniProt Name
0 DB00001 Lepirudin BiotechDrug P00734 PPP2R1B
1 DB00002 Cetuximab BiotechDrug P00533 NaN
2 DB00002 Cetuximab BiotechDrug O75015 PPP2R5B
</code></pre>
<p>如果<code>NaN</code>需要原始值:</p>
<pre><code>df2['UniProt Name'] = df2['UniProtID'].map(df1.set_index('UniProtID')['NAME'])
.fillna(df2['UniProt Name'])
print (df2)
DrugBankID Name Type UniProtID \
0 DB00001 Lepirudin BiotechDrug P00734
1 DB00002 Cetuximab BiotechDrug P00533
2 DB00002 Cetuximab BiotechDrug O75015
UniProt Name
0 PPP2R1B
1 Epidermal growth factor receptor
2 PPP2R5B
</code></pre>
<p>与<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow noreferrer">^{<cd6>}</a>-需要<code>left</code>与<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.fillna.html" rel="nofollow noreferrer">^{<cd8>}</a>或<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.combine_first.html" rel="nofollow noreferrer">^{<cd9>}</a>连接的解决方案,最后通过<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop.html" rel="nofollow noreferrer">^{<cd10>}</a>删除列:</p>
<pre><code>df = pd.merge(df2, df1, on="UniProtID", how='left')
df['UniProt Name'] = df['NAME'].fillna(df['UniProt Name'])
#alternative
#df['UniProt Name'] = df['NAME'].combine_first(df['UniProt Name'])
df.drop('NAME', axis=1, inplace=True)
print (df)
DrugBankID Name Type UniProtID \
0 DB00001 Lepirudin BiotechDrug P00734
1 DB00002 Cetuximab BiotechDrug P00533
2 DB00002 Cetuximab BiotechDrug O75015
UniProt Name
0 PPP2R1B
1 Epidermal growth factor receptor
2 PPP2R5B
</code></pre>
<hr/>
<pre><code>df = pd.merge(df2, df1, on="UniProtID", how='left')
df = df.drop('UniProt Name', axis=1).rename(columns={'NAME':'UniProt Name'})
print (df)
DrugBankID Name Type UniProtID UniProt Name
0 DB00001 Lepirudin BiotechDrug P00734 PPP2R1B
1 DB00002 Cetuximab BiotechDrug P00533 NaN
2 DB00002 Cetuximab BiotechDrug O75015 PPP2R5B
</code></pre>