Elegant way to replace values in pandas.DataFrame from another DataFrame
<p>I have a data frame that I want to replace the values in one column, with values from another dataframe. </p>

<pre><code>df = pd.DataFrame({'id1': [1001,1002,1001,1003,1004,1005,1002,1006],
                   'value1': ["a","b","c","d","e","f","g","h"],
                   'value3': ["yes","no","yes","no","no","no","yes","no"]})

dfReplace = pd.DataFrame({'id2': [1001,1002],
                   'value2': ["rep1","rep2"]})
</code></pre>

<p>I need to use a groupby with common key and current solution is with a loop. Is there a more elegant (faster)  way to do this with .map(apply) etc. I wanted initial to use pd.update(), but doesn't seem the correct way. </p>

<pre><code>groups = dfReplace.groupby(['id2'])

for key, group in groups:
    df.loc[df['id1']==key,'value1']=group['value2'].values
</code></pre>

<p>Output</p>

<pre><code>df
    id1   value1 value3
0   1001  rep1   yes
1   1002  rep2   no
2   1001  rep1   yes
3   1003  d      no
4   1004  e      no
5   1005  f      no
6   1002  rep2   yes
7   1006  h      no
</code></pre>