Created
June 23, 2016 02:46
-
-
Save jspeis/9659a7ecf256e009aa9df336e9ae1231 to your computer and use it in GitHub Desktop.
Easily import DataUSA API into 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 | |
import requests | |
def datafold(data): | |
return [dict(zip(data["headers"], d)) for d in data["data"]] | |
def api_to_df(url): | |
req = requests.get(url) | |
data = datafold(req.json()) | |
df = pd.DataFrame(data) | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment