<p>我建议首先使用<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.set_index.html" rel="nofollow noreferrer">^{<cd1>}</a>和<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.to_dict.html" rel="nofollow noreferrer">^{<cd2>}</a>创建包含所有查找文件的字典:</p>
<pre><code>d = {'ID_1' : df2.set_index('ID_1')['Monthly_MB'].to_dict(),
'ID_2' : df3.set_index('ID_2')['platform'].to_dict(),
'ID_3' : df4.set_index('ID_3')['Device'].to_dict()}
</code></pre>
<p>然后按字典的所有键循环并使用列表理解-首先按<code>;</code>拆分值如果是字符串,则按字典映射,然后按<code>join</code>返回<code>;</code>:</p>
<pre><code>for c in d.keys():
f = lambda x: ';'.join(str(d[c].get(y, '')) for y in x.split(';'))
if isinstance(x, str)
else x
df1[c] = df1[c].apply(f)
print (df1)
Name Address ID_1 ID_2 ID_3
0 Ruth D. Batie 4962 Hill Street 1557 NaN BOOST2
1 Kelley C. Rice 1074 Tipple Road NaN android NaN
2 Gary P. Kirby 1520 Robinson Court 24 android;ios BOOST2
</code></pre>