I have a file of about 50000 tweets and I want to replace all the currency symbols by words so that $10
becomes 10 dollars.
How can I do that in Python?
I can find the symbols using a regex: [$][0-9]+
. I am not sure how to replace that by words and and also interchange the positions of the number and symbol.
My tweets have only $
symbols and no other currency symbols. Please help.
re.sub(..)
is your friend.
>>> re.sub(r"\$(\d+)", r"\1 dollars", "$10")
'10 dollars'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.