0

I have downloaded and created the dataframe below. I would like to create an additional column, in which I divide the second number from a cell by the first one. To give an example, the first cell of the column should be 0.8 (because it's 4/5 = 0.8). Does anyone know how to get the numbers from the string directly and divide them?

enter image description here

Thanks in advance, any help or tips appreciated

MikeH
  • 47
  • 10

1 Answers1

1

Use:

df['Ratio'] = (df['Ratio'].str.split(' for ', expand=True)
                          .astype(float)
                          .assign(Ratio= lambda x: x[0] / x[1])['Ratio'])
ansev
  • 30,322
  • 5
  • 17
  • 31