Summarizing OpenPoliceData Data#

This notebook shows examples of the following tasks: - Summarizing available data in OpenPoliceData (OPD) - Exporting data summaries - Generating your own data summaries

[4]:
try:
    import openpolicedata as opd
except:
    import sys
    sys.path.append('../openpolicedata')
    import openpolicedata as opd
[3]:
# Get The number of unique datasets (unique state, source, agency, and table type)
print(f"The OpenPoliceData package has {opd.datasets.num_unique()} unique datasets")
The OpenPoliceData package has 212 unique datasets
[4]:
# Find how many datasets are available for full states and how many are available for individual agencies
print(f"OPD has {opd.datasets.num_sources(full_states_only=True)} datasets for all agencies in a state")
print(f"OPD has {opd.datasets.num_sources()-opd.datasets.num_sources(full_states_only=True)} datasets for individual agencies")
OPD has 9 datasets for all agencies in a state
OPD has 120 datasets for individual agencies
[5]:
# Find number of datasets from each state
opd.datasets.summary_by_state().head(10)
[5]:
Total
State
California
All State Agencies 2
Individual Agency 23
Texas 20
North Carolina
All State Agencies 1
Individual Agency 17
New York 12
Ohio 10
Arizona 9
[6]:
# Find number of datasets from each state broken down by year
opd.datasets.summary_by_state(by="year").head(7)
[6]:
Total N/A MULTI-YEAR 2022 2021 2020 2019 2018 2017 2016 ... 2014 2013 2012 2011 2010 2009 2008 2007 2006 2005
State
California ...
All State Agencies 2 0 0 0 1 2 2 2 1 1 ... 0 0 0 0 0 0 0 0 0 0
Individual Agency 23 0 18 0 5 5 4 4 4 4 ... 2 2 2 2 1 0 0 0 0 0
Texas 20 0 13 0 0 2 6 6 6 5 ... 5 2 1 1 1 1 0 0 0 0
North Carolina ...
All State Agencies 1 0 1 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
Individual Agency 17 2 14 0 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1

7 rows × 21 columns

[7]:
# Find number of datasets from each state broken down by table type
opd.datasets.summary_by_state(by="table").head(7)
[7]:
Total ARRESTS CALLS FOR SERVICE CITATIONS COMPLAINTS EMPLOYEE FIELD CONTACTS OFFICER-INVOLVED SHOOTINGS OFFICER-INVOLVED SHOOTINGS - CIVILIANS OFFICER-INVOLVED SHOOTINGS - INCIDENTS ... TRAFFIC ARRESTS TRAFFIC CITATIONS TRAFFIC STOPS TRAFFIC WARNINGS USE OF FORCE USE OF FORCE - CIVILIANS USE OF FORCE - CIVILIANS/OFFICERS USE OF FORCE - INCIDENTS USE OF FORCE - OFFICERS VEHICLE PURSUITS
State
California ...
All State Agencies 2 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 1 0 0
Individual Agency 23 0 5 0 1 0 0 0 1 1 ... 0 0 7 0 0 0 1 0 0 0
Texas 20 0 0 0 0 0 0 0 1 1 ... 1 1 5 1 2 1 0 0 0 0
North Carolina ...
All State Agencies 1 0 0 0 0 0 0 0 0 0 ... 0 0 1 0 0 0 0 0 0 0
Individual Agency 17 0 1 1 0 2 1 0 1 1 ... 0 0 7 0 0 1 0 0 1 0

7 rows × 26 columns

[8]:
# Find number of datasets for each type of table
print(opd.datasets.summary_by_table_type())
                                           Total  \
TableType
STOPS
  TRAFFIC STOPS (Only)                        66
  STOPS (All)                                 31
  PEDESTRIAN STOPS (Only)                      2
CALLS FOR SERVICE                             22
USE OF FORCE
  Single Table
    USE OF FORCE                              13
  Multiple Tables
    USE OF FORCE - CIVILIANS                   3
    USE OF FORCE - INCIDENTS                   2
    USE OF FORCE - OFFICERS                    2
    USE OF FORCE - CIVILIANS/OFFICERS          1
OFFICER-INVOLVED SHOOTINGS
  Single Table
    OFFICER-INVOLVED SHOOTINGS                12
  Multiple Tables
    OFFICER-INVOLVED SHOOTINGS - INCIDENTS     4
    OFFICER-INVOLVED SHOOTINGS - OFFICERS      4
    OFFICER-INVOLVED SHOOTINGS - CIVILIANS     4
COMPLAINTS                                     9
EMPLOYEE                                       9
ARRESTS
  ARRESTS (All)                                6
  TRAFFIC ARRESTS (Only)                       2
  PEDESTRIAN ARRESTS (Only)                    1
CITATIONS
  CITATIONS (All)                              5
  TRAFFIC CITATIONS (Only)                     4
  PEDESTRIAN CITATIONS (Only)                  2
WARNINGS
  TRAFFIC WARNINGS (Only)                      3
  PEDESTRIAN WARNINGS (Only)                   1
FIELD CONTACTS                                 2
VEHICLE PURSUITS                               2

                                                                                   Definition
TableType
STOPS
  TRAFFIC STOPS (Only)                      Traffic stops are stops by police of motor veh...
  STOPS (All)                               Contains data on both pedestrian and traffic s...
  PEDESTRIAN STOPS (Only)                   Stops of pedestrians based on 'reasonable susp...
CALLS FOR SERVICE                           Includes dispatched calls (911 or non-emergenc...
USE OF FORCE
  Single Table
    USE OF FORCE                            Documentation of physical force used against c...
  Multiple Tables
    USE OF FORCE - CIVILIANS                Use of force data may be split into several ta...
    USE OF FORCE - INCIDENTS                Use of force data may be split into several ta...
    USE OF FORCE - OFFICERS                 Use of force data may be split into several ta...
    USE OF FORCE - CIVILIANS/OFFICERS       Use of force data may be split into several ta...
OFFICER-INVOLVED SHOOTINGS
  Single Table
    OFFICER-INVOLVED SHOOTINGS                                          Shootings by officers
  Multiple Tables
    OFFICER-INVOLVED SHOOTINGS - INCIDENTS  Officer-involved shootings data may be split i...
    OFFICER-INVOLVED SHOOTINGS - OFFICERS   Officer-involved shootings data may be split i...
    OFFICER-INVOLVED SHOOTINGS - CIVILIANS  Officer-involved shootings data may be split i...
COMPLAINTS                                  Complaints of police misconduct made internall...
EMPLOYEE                                             Demographic data of the police workforce
ARRESTS
  ARRESTS (All)                                     Seizures or forcible restraints by police
  TRAFFIC ARRESTS (Only)                                  Traffic stops leading to an arrest.
  PEDESTRIAN ARRESTS (Only)                             Pedestrian stops leading to an arrest
CITATIONS
  CITATIONS (All)                           Commonly referred to as tickets, citations ind...
  TRAFFIC CITATIONS (Only)                               Traffic stops leading to a citation.
  PEDESTRIAN CITATIONS (Only)                          Pedestrian stops leading to a citation
WARNINGS
  TRAFFIC WARNINGS (Only)                                 Traffic stops leading to a warning.
  PEDESTRIAN WARNINGS (Only)                            Pedestrian stops leading to a warning
FIELD CONTACTS                              Consensual contacts between officers and the c...
VEHICLE PURSUITS                            Attempts by officers in vehicles to pursue veh...
[9]:
# Find number of datasets for each type of table broken down by year
opd.datasets.summary_by_table_type(by_year=True).head()
[9]:
Total N/A MULTI-YEAR 2022 2021 2020 2019 2018 2017 2016 ... 2013 2012 2011 2010 2009 2008 2007 2006 2005 Definition
TableType
STOPS ...
TRAFFIC STOPS (Only) 66 0 64 0 0 2 2 2 2 2 ... 2 1 1 1 1 0 0 0 0 Traffic stops are stops by police of motor veh...
STOPS (All) 31 0 30 0 0 1 1 1 0 0 ... 0 0 0 0 0 0 0 0 0 Contains data on both pedestrian and traffic s...
PEDESTRIAN STOPS (Only) 2 0 1 0 0 0 0 0 0 1 ... 1 1 0 0 0 0 0 0 0 Stops of pedestrians based on 'reasonable susp...
CALLS FOR SERVICE 22 0 14 2 8 8 8 7 7 6 ... 5 5 4 2 1 1 1 1 1 Includes dispatched calls (911 or non-emergenc...

5 rows × 22 columns

[10]:
# All returned summary tables are pandas DataFrames so they can be easily exported to CSV files
# Find number of datasets for each type of table broken down by year
opd.datasets.summary_by_table_type(by_year=True).to_csv("table_summary_by_year.csv")