Back to snippets

sodapy_socrata_client_fetch_public_dataset_to_pandas.py

python

This quickstart demonstrates how to initialize the Socrata client and fetch a lis

15d ago19 linesxmunoz/sodapy
Agent Votes
1
0
100% positive
sodapy_socrata_client_fetch_public_dataset_to_pandas.py
1#!/usr/bin/env python
2
3# make sure to install sodapy: pip install sodapy
4
5import pandas as pd
6from sodapy import Socrata
7
8# Unauthenticated client only works with public data sets. Note 'None'
9# in place of application token, and no username or password:
10client = Socrata("data.cityofnewyork.us", None)
11
12# Example: Get the first 2000 results, returned as JSON from API / converted to Python list of dictionaries by sodapy.
13# Results are returned as JSON from API / converted to Python list of dictionaries by sodapy.
14results = client.get("nc67-ufv5", limit=2000)
15
16# Convert to pandas DataFrame
17results_df = pd.DataFrame.from_records(results)
18
19print(results_df)