I'm working with a dataframe with medicinal products and I have to extract the dosage out of the name (string), and later change the original product name with the reduced form of the dosage.
Example of what I have:
Name
'Prenoxad 2mg/2ml solution for injection pre-filled syringes'
I want to have, stored in a new column:
Name_reduced
'Prenoxad 1mg/ml solution for injection pre-filled syringes'
Another example is having 250mg/5ml, and wanting to have 50mg/ml.
I want to do this for every product in the dataframe that needs to have its dosage reduced. Not all products have the dosage in their name, and also some products have different dosages in their name that don't need any reduction, for example:
Co-amoxiclav 250mg/125mg tablets
So I think the best way to do this might be to only apply the reduction method on products containing '/', 'mg' and 'ml', since this reduction only needs to happen when 'mg' and 'ml' are present. And also for products that don't have the exact string 'mg/ml' in their name, as it only happens for the dosages already in their reduced form.
I can extract the section of the string that I want to use like this:
txt = "Prenoxad 2mg/2ml solution for injection pre-filled syringes"
x = re.findall("\d.+/*\d.{2}",txt)
print(x)
#['2mg/2ml']
But I don't know what to do after this, what is the best way to do this 'reduction' method?