import pandas as pd
import requests
import json
# send a get request for 10 jokes
= requests.get("https://official-joke-api.appspot.com/jokes/ten") jk
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
= json.loads(jk.text) jok
Convert json to DF
= pd.DataFrame(jok)
jokes = ["type", "id"], inplace = True)
jokes.drop(columns 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. |