Skip to main content

Explore and load Colorado crime data.

Project description

crime    

See Github


Easily load online crime datasts. Explore available datasets from inside a python notebook, with descriptive cell outputs showing general info and descriptions of each dataset and each of its columns.

With detailed metadata, you'll even see a full list of possible categories in any text column, and a frequency count of each, without ever loading the data.


Install & Use

pip install crime
import crime as cr

Note: this library should work with any recent Python version, but it has only been tested with 3.9. If you're getting errors anywhere, check to make sure you have the latest python version.



Getting Started

First, get an App Token from Socrata. It's not required but highly recommended.

Let's look at the crime data available

cr.sources() # returns a DataFrame
image

You'll get a df with basic info on all the sources. The index, Name is the nickname with which you'll refer to the dataset moving forward. The Type column can be "Records" or "Aggregate". Aggregate is usually a small, year-by-year dataset with 30-100 rows, from which you can easily make charts.


To examine a source, pass the name of the dataset to sources(). This will make an api request to get all of its metadata.

But first, please declare your App Token. Without it, you'll get warnings and throttling.

cr.set_token('XXXXXXXXXX')

Let's see the details on crime_vs_incarceration rate. All the info below is coming from Socrata's api.

cr.sources('crime_vs_incarceration') 
Total Crime Rate vs Incarceration Rate Chart
https://dev.socrata.com/foundry/data.colorado.gov/ae3x-wvn9

Total Crime includes: Violent crimes- Murder and non-negligent manslaughter, 
forcible rape, robbery, and aggravated assault. Property crimes - Burglary,
larceny/theft, and motor vehicle theft. National or state offense totals are
based on data from all reporting agencies and estimates for unreported areas.
Rates are the number of reported offenses per 100,000 population. These
figures are based on end of calendar year populations.

COLUMNS:
-------
Year
  Field:  year
  Type:   text
  Null:   0
  Count:  31

Population
  Field:  population
  Type:   number
  Null:   0
  Count:  31
  Avg:    4019137.064516129
  Max:    5187582
  Min:    3045000
  Sum:    124593249

Violent Crime Total
  Field:  violent_crime_total
  Type:   number
  Null:   0
  Count:  31
  Avg:    16445.54838709677
  Max:    20229
  Min:    13811
  Sum:    509812

(output is truncated to save space)

Here's what you'll see for text/categorical columns...

Race
  Field:  race
  Type:   text
  Null:   30
  Count:  209078
  ITEMS:
     White  (164276)
     Black  (39469)
     Asian/Pacific Islander  (2216)
     Unknown  (1901)
     American Indian/Alaskan Native  (1216)

Now we'll load some data

cr.load('arrest_demographics')
image

You'll get a 5-row preview by default, because some datasets have several million rows. To get the full dataset:

cr.load('arrest_demographics', full=True)
image

No proper documentation yet. View the source code if needed.

If there's a dataset not yet listed in our pre-defined sources, you can use the sodapy API wrapper to retrieve it with little effort.


Getting your App Token

Not required, but without one, you'll get warnings and be subject to "strict throttling limits" though it's unclear what those limits are.

1. Create a Socrata account

You just need an email and password.

This takes you to the Colorado signup page, but your account will be universal for Socrata, so it doesn't matter.

Sign up

2. Create App Token

After verifying your email and entering your account, hit Developer Settings on the left side of the page.

image

Click "Create New App Token"

image

Only two fields are required so you can skip the rest, but 'Application Name' must be unique.

image

Copy the key

image
Where'd you find the signup link?

Find a dataset you want to work with on Open Data Network, then select "View API", and you should get to a page like this. Scroll down and find the "Sign up for an app token!" button, and continue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crime-0.0.3.tar.gz (9.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page