spsafe / README.md
joaomjr's picture
Update README.md
c651fe5 verified
---
license: mit
language:
- pt
tags:
- socioloy
- criminology
- brazil
- crime
size_categories:
- 100M<n<1B
---
# SPSafe Dataset
## About the Dataset
SPSafe is a standardized dataset of crime incident reports registered in the state of São Paulo, Brazil, from 2003 to 2022. This dataset was created to address and resolve issues of standardization, consistency, and heterogeneity found in the original data provided by the Secretariat of Public Security of the State of São Paulo (SSP/SP).
The primary goal of SPSafe is to provide a high-quality, easy-to-use resource for public safety managers, researchers, and data analysts to identify patterns, support decision-making, and aid in the development of public policies to combat crime. The data has undergone a thorough Extract, Transform, Load (ETL) process to clean, standardize, and enrich the original incident reports.
## Data Source
The data was originally sourced from the Transparency Portal of the SSP/SP, which provides monthly data on various crime categories. These original files presented several challenges, including:
* Use of proprietary file formats (.xls, .xlsx).
* Data fragmentation across a large number of files.
* Inconsistent file encodings (UTF-8 and UTF-16).
* Lack of standardization in field names, date/time formats, and municipality names.
* Poorly formatted fields with excess whitespace and special characters.
* Null values in critical fields.
## Methodology
The creation of the SPSafe dataset involved a three-module process built using the Python programming language:
1. **Extraction**: A web scraping script using the `PyAutoGUI` library was developed to download 798 data files from the SSP/SP portal, covering the years 2003 to 2022. This amounted to a total of 8GB of raw data.
2. **Transformation**: This module performed the core data cleaning and enrichment tasks:
* **Conversion**: All `.xls` files were converted to `.xlsx` using LibreOffice, and file encoding was standardized to UTF-8.
* **Standardization**: Using the `pandas` library, fields were cleaned by removing excess whitespace and special characters, standardizing text to uppercase, and unifying date and time formats.
* **Enrichment & Imputation**: Null values in the `PERIODO_OCORRENCIA` (period of occurrence) field were filled based on the `HORA_OCORRENCIA` (time of occurrence) field. New fields for vehicle make (`MARCA_VEICULO`) and model (`MODELO_VEICULO`) were created by splitting existing data.
* **Integration**: Location data was integrated with territorial division data from the Brazilian Institute of Geography and Statistics (IBGE). Inconsistent municipality names were resolved by using latitude and longitude data for a spatial join with official municipal boundaries, utilizing the `GeoPandas` library. This process added a standardized IBGE city code (`COD_IBGE`) to the dataset.
3. **Load**: The cleaned and transformed data, now in pandas DataFrames, was exported into open, non-proprietary formats (CSV and JSON), grouped by year.
## Data Dictionary
The dataset includes fields covering general information about the incident report, details about the people involved, and specifics on vehicles or cell phones where applicable. New fields were added and existing ones were improved during the transformation process.
### New Fields:
* **CODIGO_BOLETIM**: A unique identifier created by concatenating the report number and the year.
* **COD_IBGE**: The standardized 7-digit IBGE code for the municipality of the incident.
* **PONTO_CRIME**: Geographic point of the crime in WKT format.
* **MARCA_VEICULO**: The make of the vehicle involved.
* **MODELO_VEICULO**: The model of the vehicle involved.
### Significantly Improved Fields:
* **CIDADE**: The city where the crime occurred, now standardized.
* Other fields that underwent standardization include `DATA_OCORRENCIA`, `HORA_OCORRENCIA`, and `PERIODO_OCORRENCIA`.
For a complete list and description of all fields, please refer to Table 2 in the source paper.
## File Formats
The dataset is available in two open formats to ensure broad compatibility and ease of use:
* **CSV (Comma-Separated Values)**
* **JSON (JavaScript Object Notation)**
Data is organized into separate files for each year.
## Potential Applications
SPSafe is designed for a variety of uses, including:
* Integration with external datasets (e.g., income distribution, housing, public transport) for comprehensive analysis.
* Serving as a basis for training and testing machine learning algorithms to predict crime hotspots.
* Quantitative and qualitative analysis of crime trends.
* Use in data warehousing environments for strategic decision-making.
## Limitations
* **Data Availability**: The dataset is constrained by the data made available by the SSP/SP. For example, data for specific crimes like `latrocínio` (robbery-homicide) is only available from 2010 onwards, which may affect longitudinal analyses for certain crime types.
* **Irreducible Null Values**: Some fields contain null values that could not be inferred from other available data, such as the status of certain crimes.
## Availability
The SPSafe dataset is available for free download from the following repository:
* **URL**: `https://github.com/julianabfreitas/SPSafe`
## How to Cite
When using this dataset in your research, please cite the following paper:
Freitas, J. B., Clarindo, J. P., & Aguiar, C. D. (2023). SPSafe: um dataset sobre dados de criminalidade no estado de São Paulo. In *Proceedings of the V Dataset Showcase Workshop (DSW 2023)* (pp. 48-57). Sociedade Brasileira de Computação (SBC).
**DOI**: `10.5753/dsw.2023.233945`
### References
* [Freitas, J. B., Clarindo, J. P., & Aguiar, C. D. (2023). SPSafe: um dataset sobre dados de criminalidade no estado de São Paulo. *Proceedings of the V Dataset Showcase Workshop (DSW 2023)*, 48-57. DOI: 10.5753/dsw.2023.233945](https://doi.org/10.5753/dsw.2023.233945)