Back
I'm trying to preprocess the message data from one StockTwits API, how can I remove all the instances of the $name from the string in python?
For example, if a string is:
$AAPL $TSLA $MSFT are all going up!
The output would be:
are all going up!
This code would do:
>>> s = "$AAPL $TSLA $MSFT are all going up!">>> re.sub(r"\$[a-zA-Z0-9]+\s*", "", s)'are all going up!'
>>> s = "$AAPL $TSLA $MSFT are all going up!"
>>> re.sub(r"\$[a-zA-Z0-9]+\s*", "", s)
'are all going up!'
This allows the numbers in a name as well, remove the 0-9 if that's not what you want (it would remove e.g. $15 as well).
Master end-to-end Data Science through Data Science Online Courses
31k questions
32.8k answers
501 comments
693 users