I have a data table that look like this:
ID RESULT
1 blah blah asc rdsd Critical Care Time : 3,342 job ded...
2 apple asc red Critical Care Time : 322 ED none...
3 computer Critical Care Time : 7,777 cul ninea....
I want to extract the time amount after "Critical Care Time :" to make a new column so the database reads:
ID RESULT Minutes
1 blah blah asc rdsd Critical Care Time : 3,342 job ded... 3,342
2 apple asc red Critical Care Time : 322 ED none... 322
3 computer Critical Care Time : 7,777 cul ninea.... 7,777
I have code that looks like this but its still extracting all next after the minutes:
DF['Minutes'] = DF.RESULT.str.extract(r'Critical Care Time : \s*([^\.]*)\s*\ ', expand=False)
>Solution :
Try:
df["Minutes"] = df["RESULT"].str.extract(r"Critical Care Time :\s*([\d.,]+)")
print(df)
Prints:
ID RESULT Minutes
0 1 blah blah asc rdsd Critical Care Time : 3,342 job ded... 3,342
1 2 apple asc red Critical Care Time : 322 ED none... 322
2 3 computer Critical Care Time : 7,777 cul ninea.... 7,777