I have 2 dataframes :
>>> tab1
Value Sp_name
0 None ROOT
1 0.066 Genus_1_sp1
2 0.1044 Genus_2_sp1
3 0.0708 EDGE
4 0.0586 Genus_3_sp1
5 0.0083 Genus_4_sp1
and the idea is to parse another data frame such as :
>>> tab2
Old_name New_name
Genus_1_sp1_A Genus_1_sp1
Genus_2_sp1_A Genus_2_sp1
Genus_3_sp1_A Genus_3_sp1
Genus_4_sp1_A Genus_4_sp1
and in replace Sp_name in the tab1 that match the New_name in tab2, and then replace the Sp_name by the corresponding Old_name
In the exemple I should get :
>>> tab1
Value Sp_name
0 None ROOT
1 0.066 Genus_1_sp1_A
2 0.1044 Genus_2_sp1_A
3 0.0708 EDGE
4 0.0586 Genus_3_sp1_A
5 0.0083 Genus_4_sp1_A
I tried so far:
for i in tab1['Sp_name']:
found= tab2[tab2['New_name'].str.contains(i)]
if len(found) > 0:
tab1.at[i,'Sp_name'] = str(row['Old_name'])