Skip to content

Analyzes and visualizes crime data from the NYC Police Department using interactive maps and heatmaps, leveraging the NYC Open Data API.

License

Notifications You must be signed in to change notification settings

ericmaddox/nyc-crime-analytics

Repository files navigation

NYC Crime Analytics

License Issues Forks Stars Contributors

This project analyzes and visualizes crime data from the New York City Police Department. It fetches crime data using the NYC Open Data API and generates an interactive map that displays crime locations across New York City. The map includes markers for individual crime incidents and heatmaps for different crime types. Additionally, the time range of the data is displayed on the map.

Features

  • Fetches crime data from the NYC Open Data API (5uac-w243 dataset).
  • Processes the data with pandas, cleaning date columns and handling missing values.
  • Visualizes crime data using the Folium library, with markers and heatmaps for various crime types.
  • Includes a time range of the data on the map.
  • Saves the map as an HTML file for easy viewing in any web browser.

Heatmap Demo

Requirements

Before running the script, make sure you have the following Python packages installed:

  • pandas
  • folium
  • sodapy
  • dotenv

You can install these dependencies using pip:

pip install pandas folium sodapy python-dotenv

Setup

  1. Clone this repository:

    git clone https://github.com/ericmaddox/nyc-crime-analytics.git
    cd nyc-crime-analytics
  2. Create a .env file in the root directory of the project to store your Socrata API token:

    touch .env
  3. Add your API token to the .env file:

    API_TOKEN=your_socrata_api_token_here
    

    You can obtain an API token by signing up at NYC Open Data.

Usage

Once your environment is set up, you can run the nyc_crime_analytics.py script:

python nyc_crime_analytics.py

This will fetch crime data, process it, and generate an interactive HTML map. The map will be saved to a file named nyc_crime_analysis_map.html in the project directory. You can open this file in any web browser to view the crime data visualization.

File Description

  • nyc_crime_analytics.py: Main Python script that fetches and processes the crime data and generates the interactive map.
  • .env: Environment file for storing the Socrata API token securely.

Contributing

If you'd like to contribute to this project, feel free to fork the repository, create a new branch, and submit a pull request. Please ensure that your code adheres to the coding standards and includes tests where applicable.

Acknowledgments

  • NYC Open Data API for providing the crime data.
  • Socrata API for enabling access to city datasets.
  • Folium for mapping and visualization.

About

Analyzes and visualizes crime data from the NYC Police Department using interactive maps and heatmaps, leveraging the NYC Open Data API.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages