Image for post
Image for post

How to create a Pandas Dataframe from an API Endpoint in a Jupyter Notebook

Documentation for creating a Pandas Dataframe from an API

Image for post
Image for post

Step 1: Import Pandas

import pandas as pd
Image for post
Image for post

Step 2: Import Requests

import requests
import pandas as pd
import requests

Step 3: Make a GET Request from an API Endpoint

url = 'https://api.covid19api.com/summary'
r = requests.get(url)
Image for post
Image for post
Image for post
Image for post

Step 4: Extract Data from the Request using the Json() Method

json = r.json()
Image for post
Image for post
Image for post
Image for post

Step 5: Exploring our JSON using the Keys() and Type() Methods

json.keys()
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
type(json['Global'])type(json['Countries'])type(json['Date'])
Image for post
Image for post
type(json['Countries'][0])
Image for post
Image for post
Image for post
Image for post

Step 6: JSON to Dataframe

df = pd.DataFrame(json['Countries'])
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Written by

Documentation and tutorials on Python, Programming, and Data Analysis. FPL Addict. Occasionally writing about biohacking, PMing, and food.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store