import pandas as pd
import re
regexdf_data = {
'STag': ['Title_1', 'Abs_1', 'Abs_3', 'Abs_4'],
'E1': ['pacnes', 'acne|dfe|sac', 'pI', 'kera'],
'E1_CUI': ['C3477', 'C2166', 'C9871', 'C2567']
}
df3 = pd.DataFrame(regexdf_data)
df3
E1 E1_CUI STag
0 pacnes C3477 Title_1
1 acne|dfe|sac C2166 Abs_1
2 pI C9871 Abs_3
3 kera C2567 Abs_4
Now I want only acne from acne|dfe|sac value of E1 column in place of C2166 of E1_CUI column when there is Abs_1 value in STag column of the corresponding row.
I have tried this df3.loc[df3['STag'] == 'Abs_1', 'E1_CUI'] = re.split("\|",df3['E1']) but its not working.
Expected Output
E1 E1_CUI STag
0 pacnes C3477 Title_1
1 acne|dfe|sac acne Abs_1
2 pI C9871 Abs_3
3 kera C2567 Abs_4
acne? is it a match on a specific word or simply the first split on|?