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")

Retrieve json Data

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 do crabs never give to charity? Because they’re shellfish.
1 Why do chicken coops only have two doors? Because if they had four, they would be chicke...
2 Why do C# and Java developers keep breaking th... Because they use a strongly typed language.
3 Why did Sweden start painting barcodes on the ... So they could Scandinavian.
4 I saw a nice stereo on Craigslist for $1. Sell... I couldn’t turn it down.
5 What time is it? I don't know... it keeps changing.
6 Why dot net developers don't wear glasses? Because they see sharp.
7 Finally realized why my plant sits around doin... He loves his pot.
8 There are 10 types of people in this world... Those who understand binary and those who don't
9 99.9% of the people are dumb! Fortunately I belong to the remaining 1%