I have two pandas DataFrames.
df1
col1 col2
0 E8 K4
1 E6 K3
2 E8 K4
3 E8 K4
4 E8 K2
df2
group K1 K2 K3 K4
0 E6 -2 -90 24 -23
1 E7 94 -34 3 22
2 E8 7 30 100 -9
In df2, for E8 K4, the value is
df2.loc[df2['group'] == 'E8']['K4'].item()
-9
But, how could I create a new column in df1 based on df2?
The result will look like this:
col1 col2 col3
0 E8 K4 -9
1 E6 K3 24
2 E8 K4 -9
3 E8 K4 -9
4 E8 K2 30