Skip to content

Instantly share code, notes, and snippets.

@projectyotta
Created October 31, 2017 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save projectyotta/1df5d971e4ef4b0238a396f5001655bb to your computer and use it in GitHub Desktop.
Save projectyotta/1df5d971e4ef4b0238a396f5001655bb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# make sure to install these packages before running:
# pip install pandas
# pip install sodapy
import pandas as pd
from sodapy import Socrata
# Unauthenticated client only works with public data sets. Note 'None'
# in place of application token, and no username or password:
client = Socrata("data.smcgov.org", None)
# Example authenticated client (needed for non-public datasets):
# client = Socrata(data.smcgov.org,
# MyAppToken,
# userame="user@example.com",
# password="AFakePassword")
# First 2000 results, returned as JSON from API / converted to Python list of
# dictionaries by sodapy.
results = client.get("hwna-mxa3", limit=2000)
# Convert to pandas DataFrame
results_df = pd.DataFrame.from_records(results)
print(head(results_df))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment