Created
December 15, 2018 22:03
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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