I'd like to replace the values in valcol
with the values in the column which is the value. Suppose you have df looking something like below:
col1 col2 col3 valcol
0 a d g col1
1 b e h col1
2 c f i col2
I'd like the valcol_new
to become this:
col1 col2 col3 valcol valcol_new
0 a d g col1 a
1 b e h col1 b
2 c f i col2 f
How would one do this?
df for testing:
df = pd.DataFrame({'col1': ['a', 'b', 'c'], 'col2': ['d', 'e', 'f'], 'col3': ['g', 'h', 'i'], 'valcol': ['col1', 'col1', 'col2']})