I am trying to replace fractions in a string that come in different formats. Some of the formats look like 1/2 , 1 1/2, 1-1/2.
Input='This is the first fraction 1/2'
Input_two='This is the second fraction 3-1/8'
Input_three='This is the third fraction 20 1/4'
Output='This is the first fraction 0.5'
Output_two='This is the first fraction 3.12'
Output_three='This is the first fraction 20.25'
What I have tried:
df['col]=df['col'].apply(lambda x: re.sub('\d\d?\d?.?\d+/\d+','1.5',str(x))
But this only works if you put the value in each time and a thousand different fractions
I have also tried from fractions import Fraction and from __future__ import division but cannot get these to work on strings.
pandastag.