# Python&R: Learning network analysis, networkx ver. 3

Last Updated on May 8, 2022 by shibatau

## I. What shall we learn?

Let’s learn the basics of network analysis with Python and R.

You can learn how to download movie data from The Movie Database and transform them to the data for creating network graphs from the following post:

## II. Get your API key

A TMDB user account is required to request an API key. Sign up TMDB and get an API key at TMDB API.

## III. How to get data via API

You can get the movie ID for a film on the page of the film and put it in the scripts shown in the the post above. For example, you can get the data for “The Power of the Dog” with the following code:

If you want to get the release date, run the following script:

# fetch the basic data for Dune as JSON
query = "https://api.themoviedb.org/3/movie/" + "600583" + "?api_key=" + api_key + "&language=en-US"
response =  requests.get(query)
array_b = response.json()
# show the budget
array_b['release_date']

The “query” may look confusing but you will understand what it means clearer when you learn it creates the following URL.

https://api.themoviedb.org/3/movie/600583?api_key=YOURAPI_KEY&language=en-US

Please access the page with your browser, and you can see the raw data that you will fetched.

Now let’s get a data frame of the titles and budgets of the films nominated for Oscar 2022 using For Loops and the zip function.

You can see the scripts on Google Colaboratory though they are not completed:

## IV. Create network graphs

Following the the post linked above, you can get a DataFrame of ‘edges’ for “The Power of the Dog”— each actor gets a connection to every other actor. The following graph is a network graph with some actors highlighted created with NetworkX.

## Rsourses

An Introduction to Social Network Analysis with NetworkX: Two Factions of a Karate Club

What is Network Analysis?

Applied Graphical Network Analysis using Python

Network Analysis using R

Preparing Network Data in R