Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract Text After a String

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading