LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Regular Expressions in Python

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Import the re module
____

# Write the regex
regex = ____"____"

# Find all matches of regex
print(re.____(____, ____))
Code bearbeiten und ausführen