Hi there I am trying to accomplish something similar to the mid function in excel with a column in a pandas dataframe in python. I have a column with medication names + strengths, etc of variable length. I just want to pull out the first "part" of the name and place the result into another column in the dataframe.
Example:
Dataframe column
MEDICATION_NAME acetaminophen 325 mg a-hydrocort 100 mg/2 ml
Desired Result
MEDICATION_NAME GENERIC_NAME acetaminophen 325 mg acetaminophen a-hydrocort 100 mg/2 ml a-hydrocort
What I have tried
df['GENERIC_NAME'] = df['MEDICATION_NAME'].str[:df['MEDICATION_NAME'].apply(lambda x: x.find(' '))]
Basically I want to apply the row specific result of
df['GENERIC_NAME'] = df['MEDICATION_NAME'].apply(lambda x: x.find(' '))
to the
str[:]function?
Thanks