Issue
I have a dataframe column looks like this
data
Membership 1 year
Individual - 10 years:
Membership 2019-2024
I want to extract the number before the keyword 'year'. I'd like to get output:
data contract_years
Membership 1 year 1
Individual - 10 years: 10
Membership 2019-2024
I tried
\d{2}+(?=year)
which is obviously wrong. Any suggestion will be really helpful, thanks.
Solution
df['contract_years'] = df['data'].str.extract('(\d+) year')
Answered By - Alberto Hanna
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.