Retrieve json Data

API Jokes - JSON to df

This Official Joke API returns random jokes from a database.

Case Study

Send a GET request to the API

Retrieve 10 jokes in json format

Convert json to df

Drop the type and id columns

Send Get Request

import pandas as pd
import requests
import json

# send a get request for 10 jokes
jk = requests.get("https://official-joke-api.appspot.com/jokes/ten")
jok = json.loads(jk.text)

Convert json to DF

jokes = pd.DataFrame(jok)
jokes.drop(columns = ["type", "id"], inplace = True)
jokes
setup punchline
0 Why did the programmer's wife leave him? He didn't know how to commit.
1 How do locomotives know where they're going? Lots of training
2 What's blue and not very heavy? Light blue.
3 Have you ever heard of a music group called Ce... They mostly wrap.
4 What is the most used language in programming? Profanity.
5 A grocery store cashier asked if I would like ... I told her 'No, thanks. The carton works fine.'
6 How many bones are in the human hand? A handful of them.
7 Why did the math book look sad? Because it had too many problems.
8 Where does Napoleon keep his armies? In his sleevies.
9 Why couldn't the lifeguard save the hippie? He was too far out, man.