Filter API Get in Python

Viewed 662

I'm using Python to do some data cleaning/task automation, but am having a hard time reading in data through an API with multiple conditions. My data is as follows:

url =  "https://data.cityofnewyork.us/resource/erm2-nwe9.json?descriptor='Social Distancing' or descriptor='Face Covering Violation' or descriptor='Business not in compliance'"
r = requests.get(url)
x = r.json()
df = pd.DataFrame(x)

When I pull it, it only provides me with data where the descriptor is 'Social Distancing'. Any tips on how to change this so that it filters for all of the needed data?

1 Answers

Make three requests and merge their responses:

    def get_data(filter):
            url =  "https://data.cityofnewyork.us/resource/erm2-nwe9.json?descriptor='{0}'".format(filter)
            r = requests.get(url)
            return pd.DataFrame(r.json())


    df = pd.concat([
      get_data('Social Distancing'),
      get_data('Face Covering Violation'),
      get_data('Business not in compliance')

    ])
Related