Learn practical skills, build real-world projects, and advance your career

Crime Hotspot Finder

Idea

The idea of the research is to create a prototype of an application that can help police in a town/city to be able to view a crime map of the area once they give the inputs of "day", "month", "hour". At any particular timeframe determined by a day, a month and a year; the prototype will output a map of Chicago with all the 25 districts in the state of Chicago displayed and shaded according to the intensity of crime in that particular timeframe.

Below is the basic UI of our prototype

Chicago%20Crime%20Hotspot%20UI.png

# Loading the libraries

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime
import seaborn as sns

Creating the Dataset

  • Append all datasets from 2015-2019 [5 years]
  • The final dataset should have 22 columns exactly
  • Missing data has to be handled
'''Let's write code to automate the creating of our dataset'''

file_names = ['crimes_2015.csv','crimes_2016.csv','crimes_2017.csv','crimes_2018.csv','crimes_2019.csv']

def create_df(filenames):
    main_df = pd.read_csv(filenames[0])
    print("Finished Loading Chicago Crime Dataset File for the year "+filenames[0][7:11]+".")
    main_df = main_df[list(main_df.columns[:22])]
    for file in filenames[1:]:
        print("Finished Loading Chicago Crime Dataset File for the year "+file[7:11]+".")
        df_temp = pd.read_csv(file)
        df_temp = df_temp[list(df_temp.columns[:22])]
        main_df = main_df.append(df_temp, ignore_index=True)
    print("All data files loaded onto the Main Dataframe.\nYOU ARE READY TO GO!\n")
    return main_df

main_df = create_df(file_names)
orig_shape = main_df.shape
print("The Number of Crimes: "+ str(main_df.shape[0]))
print("\nThe Columns: "+ str(main_df.shape[1]))
Finished Loading Chicago Crime Dataset File for the year 2015. Finished Loading Chicago Crime Dataset File for the year 2016. Finished Loading Chicago Crime Dataset File for the year 2017. Finished Loading Chicago Crime Dataset File for the year 2018. Finished Loading Chicago Crime Dataset File for the year 2019. All data files loaded onto the Main Dataframe. YOU ARE READY TO GO! The Number of Crimes: 1146382 The Columns: 22