Extracting a person's age from unstructured text in Python

前端 未结 5 1762
栀梦
栀梦 2021-01-18 23:08

I have a dataset of administrative filings that include short biographies. I am trying to extract people\'s ages by using python and some pattern matching. Some example of s

5条回答
  •  自闭症患者
    2021-01-18 23:53

    import re 
    
    x =["Mr Bond, 67, is an engineer in the UK"
    ,"Amanda B. Bynes, 34, is an actress"
    ,"Peter Parker (45) will be our next administrator"
    ,"Mr. Dylan is 46 years old."
    ,"Steve Jones, Age:32,"]
    
    [re.findall(r'\d{1,3}', i)[0] for i in x] # ['67', '34', '45', '46', '32']
    

提交回复
热议问题