Are they bots?
The company that you are working for asked you to perform a sentiment analysis using a dataset with tweets. First of all, you need to do some cleaning and extract some information.
While printing out some text, you realize that some tweets contain user mentions. Some of these mentions follow a very strange pattern. A few examples that you notice: @robot3!
, @robot5&
and @robot7#
To analyze if those users are bots, you will do a proof of concept with one tweet and extract them using the .findall()
method.
You write down some helpful metacharacters to help you later:
\d
: digit
\w
: word character
\W
: non-word character
\s
: whitespace
The text of one tweet was saved in the variable sentiment_analysis
. You can use print(sentiment_analysis)
to view it in the IPython Shell.
This exercise is part of the course
Regular Expressions in Python
Exercise instructions
- Import the
re
module. - Write a regex that matches the user mentions that starts with
@
and follows the pattern, e.g.@robot3!
. - Find all the matches of the pattern in the
sentiment_analysis
variable.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import the re module
____
# Write the regex
regex = ____"____"
# Find all matches of regex
print(re.____(____, ____))