1. Learn
  2. /
  3. Courses
  4. /
  5. Analyzing Social Media Data in Python

Connected

Exercise

Creating retweet network

Social media is, by nature, networked data. Twitter networks manifest in multiple ways. One of the most important types of networks that appear in Twitter are retweet networks. We can represent these as directed graphs, with the retweeting user as the source and the retweeted person as the target. With Twitter data in our flattened DataFrame, we can import these into networkx and create a retweet network.

For this exercise and the rest of this course we'll be using a dataset based on the 2018 State of the Union speech given by Donald Trump. Those tweets have been loaded for you in sotu_retweets.

Instructions

100 XP
  • Import networkx as nx.
  • Use the user's screen name as the source argument.
  • Use the retweeted user's screen name as the target argument.
  • Ensure that the network is a directed graph in the create_using argument.