I have a sentence that consists of numbers and words. I am looking for a solution to remove numbers except at the beginning. I have tried the following code, but it's removing all the numbers.
x = '45 is fourth five 45 when 9 and 5 are multiplied'
re.sub('\d', '', x)
Its output was
'is Fourth five when and are multiplied'
But need the output in the following manner.
'45 is Fourth five when and are multiplied'
Note:
The number may or may not present at the beginning.
Inside the sentence, there can be alphanumeric (
460KG
), then it should be changed (KG). That means, except at the beginning, the number should be removed elsewhere. example :
6-apples price is 56Rs
I need an output as
6-apples price is Rs