Twitter data to DataFrame
Now that you have the Twitter data in a list of dictionaries tweets_data, where each dictionary corresponds to a single tweet, it's time to extract the text of the tweets, along with the language of the tweet. The text in a tweet t1 is stored as the value t1['text']; similarly, the language is stored in t1['lang']. Your task is to build a DataFrame in which each row is a tweet and has two columns, one for text, the other for lang.
This exercise is part of the course
Importing Data in Python
Exercise instructions
- Use
pd.DataFrame()to construct a DataFrame of tweet texts and languages: to do so, the first argument should be a list of dictionaries and the second argument a list of the keys you wish to have as columns; assign the result todf. - Print the head of the DataFrame.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import package
import pandas as pd
# Build DataFrame of tweet texts and languages
df = pd.DataFrame(____, ____)
# Print head of DataFrame