<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Working with data from an API
Web APIs are now a common way to interact with data, and many governments now have open data portals that offer access via API. Socrata is a common vendor.
Here, we're going to tap into the API feed of a dataset of vacant buildings in St. Paul.
Import the modules we need
Step1:  Fetch the page and get the JSON
Step2:  Filter the data
Looks like we're dealing with a list of dictionaries. Maybe our goal here is to filter out everything except the vacant single-family residences.
Let's use a new thing called a list comprehension -- really handy when you want to filter a group of things and store the result in a variable.
<ASSISTANT_TASK:>
Python Code:
import json
import requests
Explanation: Working with data from an API
Web APIs are now a common way to interact with data, and many governments now have open data portals that offer access via API. Socrata is a common vendor.
Here, we're going to tap into the API feed of a dataset of vacant buildings in St. Paul.
Import the modules we need
End of explanation
# URL
URL = 'https://information.stpaul.gov/resource/rfbb-x7za.json'
# use the json() method, which converts the json into Python objects
vb_data = requests.get(URL).json()
# print to see what we're working with
print(vb_data)
Explanation: Fetch the page and get the JSON
End of explanation
sfr_vb = [x for x in vb_data if x['dwelling_type'] == 'Single Family Residential']
print(len(sfr_vb), 'SFR of', len(vb_data), 'total')
Explanation: Filter the data
Looks like we're dealing with a list of dictionaries. Maybe our goal here is to filter out everything except the vacant single-family residences.
Let's use a new thing called a list comprehension -- really handy when you want to filter a group of things and store the result in a variable.
End of explanation
<END_TASK>