I have a dataframe df
.
V1 V2 V3
A 1 3
A 2 8
B 4 12
C 3 2
R 8 9
I also have a list lst
that works as a map, I can pass a string as an index to the list and it will return a string value. E.g.
lst[["A"]] => "AB"
lst[["B"]] => "BA"
lst[["C"]] => "FE"
lst[["R"]] => "WE"
What I want is to create a new column for df
in relation to an existing column. The first column in df
will work as the key index to the list and it will return in the same row in the new column the respective value.
I would like to end up with:
V1 V2 V3 V4
A 1 3 AB
A 2 8 AB
B 4 12 BA
C 3 2 FE
R 8 9 WE
Also I want to avoid for-loops since my actual data is very large and also because I would like to see a different and elegant solution. Is there a way to do the above?
Thank you in advance.