Previously, I'm asking How to update series based on other pandas dataframe, and there exist 3 answers, but 3 of them give caveats, usually I ignoring this, but this is for production purpose, so I'cant. Here's the answer and the caveat:
1
s = df2.set_index('Nation')['Capital City']
df1['Capital'] = df1['Country'].map(s).fillna(df1['Capital'])
caveat
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
2
df1['Capital'] = df1['Country'].replace(s)
caveat
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
3
s = df2.set_index('Nation')['Capital City']
df1['Capital'].update(df1['Country'].map(s))
caveat
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
exec(code_obj, self.user_global_ns, self.user_ns)
/home/ubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
How to reduce the caveat