Assignment 2: Game of Thrones Network

Hannah Johnston
INST414: Data Science Techniques
3 min readMay 12, 2023

The data I used for this assignment came from a Game of Thrones API: https://anapioficeandfire.com/

Where each character to ever appear in the show had their own entry, with 10 entries per page and 215 pages total. Each character’s entry had information such as their name, any allegiance they have, episodes they appeared in, and other relevant information. In order to get a list of all the characters, I created a for loop to cycle through the pages of the API and append each character’s dictionary of characteristics on each page into one big list.

To create my network, I decided to have the characters be nodes and their allegiances be the way the nodes were connected, or the edges. In the network, allegiances can be defined as belonging to or being affiliated with a certain house, something that was noted by a key and value pair in the dictionaries of characteristics for each character. As far as data cleaning, there were numerous houses with no members so in order to get rid of them I created another for loop, that appended the house to a comprehensive list of houses if and only if the “members” section had at least one person in it, so essentially just ensuring that it wasn’t empty.

Once I had created the network, I used the Network X library as well as Gephi in order to visualize it. The layout I chose was the Fruchterman Reingold format. This format is a layout algorithm that treats edges like springs that move the vertices. From here, visible clusters started to form.

Gephi rendering of the Game of Thrones Network

Then I also used Network X to get the bridges. In class we learned that bridges act as gateways and in the context of the network I created, bridges would represent characters with connections to multiple houses. It only took one line of code to get the list of bridge characters, as network X has a very helpful package that makes it really easy to identify bridges, however, the list was in the format of URLs for each character’s web page, which wasn’t useful as it didn’t display the names of the bridge characters so then I had to loop through the list and take the last three alphanumeric characters of each url and put it through the character list to actually get the names of the characters. Once I had managed to do that, the output was the following list which includes Andros Brax, Clarence Crabb, Baelor Hightower, and more.

List of bridge characters

We can interpret this list as characters who are “important” nodes in our network, meaning they have a lot of connections, and also act as bridges which as I said in this case means they have affiliations with multiple houses.

Potential limitations to this analysis may include a few things. One, the definition of importance of a character in this network. The idea of importance of a character overall is kind of subjective as some may consider “main” characters to be the most important, whereas in this network analysis, importance means something else. Additionally, I have never in my life seen or read Game of Thrones which could definitely affect my understanding of how to code this network.

Github link: https://github.com/hannahj3/INST414/blob/main/INST414-a2.ipynb

--

--