I have sentences in which sometimes the numbers are written as words, e.g.:
He takes classes of yoga two times per week.
I need to replace numbers written as words by numbers:
He takes classes of yoga 2 times per week.
In case of He takes classes of yoga twice per week.
, it should be left as it is.
I found a library called word2number
that converts words to numbers (link). But how can I update a sentence to get He takes classes of yoga 2 times per week.
?
from word2number import w2n
w2n.word_to_num('He takes classes of yoga two times per week.')
# output: 2