0

I have a column in a Dataset where the time format is in 'aHrs bMin' .I need to convert this string to float value.

Example

Input = 2H 30M Output = 2.5

martineau
  • 119,623
  • 25
  • 170
  • 301
vishnu
  • 11

1 Answers1

1

you can make a function for that,

import re

def gettf(s):
  sh, sm ="0","0"
  vals= s.split(" ")
  sh = vals[0]
  if len(vals)>1:
    sm = vals[1]
  t = float(re.findall("\d+", sh)[0]) + float(re.findall("\d+", sm)[0])/60  
  return t

example :

print(gettf("5H 45M"))

output: 5.75

Eshaka
  • 974
  • 1
  • 14
  • 38
  • Actually the column also contains single hrs value like '2h' , '3h',... without having the 'm'(min) value.so the above code is throwing error. Please help to resolve the same too. – vishnu Dec 03 '19 at 15:01
  • @vishnu accept the answer if it helped, I edited it – Eshaka Dec 04 '19 at 06:18