import os
import math
import requests
import json
import urllib3
import pandas as pd
results = []
url = 'https://data.wprdc.org/api/3/action/datastore_search?offset=0&limit=1&resource_id=1797ead8-8262-41cc-9099-cbc8a161924b'
http = urllib3.PoolManager()
row_count = int(requests.get(url).json()['result']['total'])
segments_int = math.floor(row_count / 10000)
segments_dec = row_count / 10000
#r = requests.get(f'https://data.wprdc.org/api/3/action/datastore_search?offset={i}&limit=10000&resource_id=1797ead8-8262-41cc-9099-cbc8a161924b').json()['result']['records']
for i in range(segments_int + 1):
i = i * 10000
r = requests.get(f'https://data.wprdc.org/api/3/action/datastore_search?offset={i}&limit=10000&resource_id=1797ead8-8262-41cc-9099-cbc8a161924b').json()['result']['records']
for x in r:
results.append(x)
df = pd.json_normalize(results)
#df
df.to_csv('police_output.csv')
raw_file_in = 'police_output.csv'
rawData = pd.read_csv(raw_file_in, usecols = ['OFFENSES'])
rawData
OFFENSES | |
---|---|
0 | 3921 Theft by Unlawful Taking or Disposition. |
1 | 3304 Criminal Mischief. |
2 | 9093 Indirect Criminal Contempt |
3 | 9999 9999 - (Misc. Incident): |
4 | 2709(a) Harassment. |
... | ... |
3127 | 2705 Recklessly Endangering Another Person. / ... |
3128 | 3503 Criminal Trespass |
3129 | 9489 Found Property |
3130 | 9489 Found Property |
3131 | 3503 Criminal Trespass |
3132 rows × 1 columns