Learn practical skills, build real-world projects, and advance your career
alt

APIs, JSON files, and Data Clearning

~ Evan Marie Carr

FBI Most Wanted API:

  • does not require an api key
  • has very little documentation aside from a few examples
  • fairly simple and straight forward
import pandas as pd
import requests
import json
from IPython.display import HTML
import numpy as np
pd.options.display.max_columns = 60

Importing Data:

These are the specific methods used below (each has linked documentation):

Example Searches from FBI Most Wanted Site:

  • These search examples are the extent of the documentation the FBI Most Wanted website gives as documentation for how to use its API
# Data from Atlanta field office
response = requests.get('https://api.fbi.gov/wanted/v1/list', params={
    'field_offices': 'atlanta'
})

data = json.loads(response.content)
print("From the Atlanta field office: ", data['total'])
print(data['items'][0]['title'], "\n")

# Second page of data from entire list
response = requests.get('https://api.fbi.gov/wanted/v1/list', params={
    'page': 2
})

data = json.loads(response.content)
print("Page No.: ", data['page'])
print(data['items'][0]['title'], "\n")

# ----------------------------------------------------------------------- #

# Entire list, which is imported only 1 page at a time
response = requests.get('https://api.fbi.gov/wanted/v1/list')
data = json.loads(response.content)

database_length = data['total']

print("Length of entire most wanted list: ", data['total'])
print(data['items'][0]['title'], "\n")
From the Atlanta field office: 13 DIEGO TREJO Page No.: 2 KRISTIN DENISE SMART Length of entire most wanted list: 957 JEANINE DE RIDDERE