ComenzarEmpieza gratis

Loading and accessing tweets

In the video, we loaded a tweet we collected using tweepy into Python. Tweets arrive from the Streaming API in JSON format and need to be converted into a Python data structure.

In this exercise, we'll load a single tweet into Python and print out some fields.

The tweet JSON has been loaded for you and is stored in tweet_json.

Este ejercicio forma parte del curso

Analyzing Social Media Data in Python

Ver curso

Instrucciones del ejercicio

  • Import the json module.
  • Convert the tweet JSON stored in tweet_json from JSON to Python object using json's .loads() method.
  • Print the tweet text and id using the appropriate keys.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# Load JSON
import ____

# Convert from JSON to Python object
tweet = ____.____(tweet_json)

# Print tweet text
print(tweet[____])

# Print tweet id
print(tweet[____])
Editar y ejecutar código