Skip to content

Instantly share code, notes, and snippets.

@samredai
Created December 15, 2018 22:03
Show Gist options
  • Save samredai/5ac0ba0825eaf4bc0660927b91c0ab2f to your computer and use it in GitHub Desktop.
Save samredai/5ac0ba0825eaf4bc0660927b91c0ab2f to your computer and use it in GitHub Desktop.
Python: Convert a flat JSON response from a REST-API into a pandas DataFrame
import pandas as pd
improt requests
#Use requests to hit the API
response = requests.get('https://official-joke-api.herokuapp.com/random_ten')
#Convert the JSON response to a list of dictionaries using json()
json = response.json()
#Create a pandas DataFrame from the list of dictionaries
jokes_df = pd.DataFrame(json)
print(jokes_df.columns)
#Index(['id', 'punchline', 'setup', 'type'], dtype='object')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment