我有两个数据框,一个带有标准国家代码和国家名称,另一个只有国家名称。
我想在df2
中添加一个新列,如果值df1.iso == df2.id
匹配,则该列应包含来自df1
的国家名称。
df1
Country iso
Afghanistan AFG
Afghanistan AFG
Afghanistan AFG
...
以及df2
id
AFG
AFG
AFG
AFG
...
我尝试了这个:
post['country'] = pre['Country'].where(pre['iso'] == post['id'])
但是我遇到了一个错误
ValueError:只能比较标签相同的Series对象