API's with Python

Free Video Tutorial and Guide

In this video, we're going to look at how to manage data using API's in Python.

Video Transcription

Hi, my name is Art, and in this video I'm going to show you how to read data from APIs and convert that data into a Python data structure such as a Pandas DataFrame.

To use Pandas, you need to import it: `import pandas as pd`.

You also need to import the Requests Library, which helps Python to get online and send requests to a server for data. Most APIs require registration and sometimes require a credit card. To avoid this, we can use the Rick and Morty API which is free.

We can use the `get` method from the Requests Library to send a request to a server and get data. We will assign this data to a variable called `raw`, since it's a response. We can then parse this data, which most likely will come in the form of JSON (JavaScript Object Notation). JSON looks like a dictionary and we can use `.keys()` to get the options.

We can then grab the values we want, such as `name`, `status`, and `species`, and use dictionary notation to get them. Now we can initialize the DataFrame and use `pd.json_normalize()` to convert the data into a DataFrame. We can assign it to a variable called `df` and then do something else with it, such as writing it into a text file or a SQL database.

How to Learn Python

Master Python with hands-on training. Python is a popular object-oriented programming language used for data science, machine learning, and web development. 

Yelp Facebook LinkedIn YouTube Twitter Instagram