med2['Medication'] = ["Terazosin Hydrochloride (Terazosin) oral capsule", "simvastatin oral tablet", "zithromax z-pak (azithromycin) oral tablet", "depo-medrol (methylprednisolone) injectable suspension", "zovirax topical (acyclovir topical) topical ointment", "nystatin oral suspension"]
med3 = pd.DataFrame(med2) # Made a dataframe to try to fix some error messages
med3 = med3['Medication'].str.lower()
I would like to do two things:
- select the medication name (for example above, "terazosin hydrochloride") and
- select the generic name between the parentheses(for the example above, "terazosin").
For #1, I made a list of "stop" words/characters (my real list is longer than the above example):
stop = ['(', 'oral', 'nasal', 'inhalation', 'topical', 'sublingual', 'opthalmic', 'otic', 'rectal', 'injectable', 'transdermal', 'vaginal', 'intramuscular', 'dose', 'suspension', 'subcutaneous']
med3['MedShort'] = med3['Medication'][:stop]
For #2, I made "Index" and "End":
Index = med3['Medication'].find('(')
End = med3['Medication'].find(')')
med3['MedGeneric'] = med3['Medication'][Index:End]
But oh boy, is it not working. Do you have any recommendations? I would appreciate it!
Edited for consistent variable naming, with apologies.
And for clarification, Medication is not consistent. Most follow the pattern of "medication (generic) administration route" but a significant number follow the pattern of medication administration route". Thank you for your patience, apologies that I was not clear. \