Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

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!

1 Answer

0 votes
by (36.8k points)

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!'

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

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 26, 2019 in Python by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...