LoslegenKostenlos loslegen

Finding keywords

Counting known keywords is one of the first ways you can analyze text data in a Twitter dataset. In this dataset, you're going to count the number of times specific hashtags occur in a collection of tweets about data science. To this end, you're going to use the string methods in the pandas Series object to do this.

pandas and numpy have been imported as pd and np, respectively. A more fully-featured flatten_tweets and data_science_json have also been loaded for you.

Diese Übung ist Teil des Kurses

Analyzing Social Media Data in Python

Kurs anzeigen

Anleitung zur Übung

  • Flatten the tweets with flatten_tweets() and store them in flat_tweets.
  • Convert tweets to DataFrame using the pandas DataFrame constructor.
  • Find mentions of #python in 'text', ignoring case.
  • Print proportion of tweets mentioning #python by summing python with np.sum() and dividing it by the total number of tweets.

Interaktive Übung

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

# Flatten the tweets and store them
____ = ____(____)

# Convert to DataFrame
ds_tweets = ____.____(____)

# Find mentions of #python in 'text'
python = ____[____].____.____(____, ____)

# Print proportion of tweets mentioning #python
print("Proportion of #python tweets:", ____ / ____)
Code bearbeiten und ausführen