I've been trying to solve this in a clean manner, but have been failing remarkably on this task.
Going strait to the point... I have 2 dataframes:
df1
anID siID daID
0 A 0 0
1 D 0 0
2 E 0 0
3 F 0 0
4 G A D
5 H E D
6 B 0 0
7 I E M
8 L F 0
9 M B H
10 N A D
df2
map_id renum_id
0 A 1
1 C 2
2 B 3
3 E 4
4 D 5
5 F 6
6 Q 7
7 V 8
8 H 9
9 G 10
10 N 11
Basically, df1 is a dataframe with identification codes, df2$renum_id has the new codes to replace the existing ones and df2$map_id is the map which to guide the recoding of df1's columns.
Now I need a clean and light/fast way to get the corresponding renum_id value (using map_id as a key) for all 3 columns in df1 (anID, siID, daID). Basically, I want it to give me the corresponding renum_ID for each letter, and keep the 0 (zero) for zeros in df1.
So, I need a df3 like this:
anID siID daID anID/ siID/ daID/
0 A G 0 1 10 0
1 D E A 5 4 1
2 E 0 0 4 0 0
3 F B D 6 3 5
4 G A D 10 1 5
5 H E D 9 4 5
6 B 0 0 2 0 0
7 N A D 11 1 5
It's probably something really simple, but I've been trying with pd.merge and couldn't come up with something to solve my problem.
Dataframes have something around hundreds of thousands of lines, that's why I insist in the need of a "light" way to solve it.
Thanks everyone in advance.