I have a df that contains strings with multiple data that I want to parse and store as a dictionary. I would like to store PubMed Identifier as a pmid key and thew following digits as its values, Embase as euid and the following digits, NCT as trialid and the following number (no space), and disregard the numbers on there own or disregard PubMed Identifier/Embase without trailing/associated digits.
data = {"ORN": [1, 2, 3, 4],
"EN": ["PubMed Identifier 27955689", "PubMed Identifier 8010359Embase 24208639", "PubMed Identifier 12237786Embase 35148801", "PubMed Identifier NCT02360007 12537613"]
}
df = pd.DataFrame(data=data)
ORN EN
0 1 PubMed Identifier 27955689
1 2 PubMed Identifier 8010359Embase 24208639
2 3 PubMed Identifier 12237786Embase 35148801
3 4 PubMed Identifier NCT02360007 12537613
desired_df
ORN EN
0 1 {"pmid": 27955689}
1 2 {"pmid": 8010359, "euid": 24208639}
2 3 {"pmid": 12237786, "euid": 35148801}
3 4 {"trialid": 02360007}
I can't understand what I should do wrt best approach. My idea of splitting the string across columns with .split(expand=True) and then reordering the columns and then merging back using a to_dict() is the best I can think of but any better suggestions would be great. String manipulations is something I need improving at.