Detailed Report: Crime Analysis in Los Angeles
Overview
This project aims to analyze crime data from the Los Angeles Police Department (LAPD) to identify patterns in criminal behavior. By analyzing the frequency of crimes across different time periods, locations, and victim demographics, the goal is to provide insights that can assist in effectively allocating law enforcement resources.
###We explore the crimes data through several steps, including:
Identifying trends in crime frequency by hour of the day.
Investigating locations with high concentrations of night-time crimes.
Analyzing the age distribution of victims.
Providing actionable insights for resource allocation based on data patterns.
Los Angeles, California 😎. The City of Angels. Tinseltown. The Entertainment Capital of the World!
Known for its warm weather, palm trees, sprawling coastline, and Hollywood, along with producing some of the most iconic films and songs. However, as with any highly populated city, it isn't always glamorous and there can be a large volume of crime. That's where you can help!
You have been asked to support the Los Angeles Police Department (LAPD) by analyzing crime data to identify patterns in criminal behavior. They plan to use your insights to allocate resources effectively to tackle various crimes in different areas.
The Data
They have provided you with a single dataset to use. A summary and preview are provided below.
It is a modified version of the original data, which is publicly available from Los Angeles Open Data.
crimes.csv
| Column | Description |
|---|---|
'DR_NO' | Division of Records Number: Official file number made up of a 2-digit year, area ID, and 5 digits. |
'Date Rptd' | Date reported - MM/DD/YYYY. |
'DATE OCC' | Date of occurrence - MM/DD/YYYY. |
'TIME OCC' | In 24-hour military time. |
'AREA NAME' | The 21 Geographic Areas or Patrol Divisions are also given a name designation that references a landmark or the surrounding community that it is responsible for. For example, the 77th Street Division is located at the intersection of South Broadway and 77th Street, serving neighborhoods in South Los Angeles. |
'Crm Cd Desc' | Indicates the crime committed. |
'Vict Age' | Victim's age in years. |
'Vict Sex' | Victim's sex: F: Female, M: Male, X: Unknown. |
'Vict Descent' | Victim's descent:
|
'Weapon Desc' | Description of the weapon used (if applicable). |
'Status Desc' | Crime status. |
'LOCATION' | Street address of the crime. |
# Re-run this cell
# Import required libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
crimes = pd.read_csv("crimes.csv", dtype={"TIME OCC": str})
crimes.head()1. Peak Hour of Crime
The first analysis aimed to determine the hour of the day when crimes were reported most frequently. By extracting the hour from the TIME OCC column, we analyzed the frequency of crimes during each hour of the day.
# Import required libraries
import pandas as pd
# Load the dataset
crimes = pd.read_csv("crimes.csv", dtype={"TIME OCC": str})
# 1. Which hour has the highest frequency of crimes?
# Convert 'TIME OCC' to a numeric type for easier analysis
crimes['TIME OCC'] = pd.to_numeric(crimes['TIME OCC'], errors='coerce')
# Extract the hour from the 'TIME OCC' column
crimes['hour'] = crimes['TIME OCC'] // 100 # Integer division to extract hour (24-hour format)
# Find the hour with the highest frequency of crimes
peak_crime_hour = crimes['hour'].mode()[0] # Mode returns the most common value (highest frequency)
print(f"The hour with the highest frequency of crimes is: {peak_crime_hour}")
Findings:
The hour with the highest frequency of crimes was 12, indicating that crimes tend to spike in the evening hours. This time frame should be a focus for patrols and crime-prevention strategies.
2. Night-Time Crime Location
Next, we focused on crimes that occurred between 10 PM and 3:59 AM, also known as night-time crimes, to identify which geographic area had the largest number of such incidents.
# Which area has the largest frequency of night crimes (crimes committed between 10pm and 3:59am)?
# Filter the dataset for crimes between 10pm (22:00) and 3:59am (03:59)
night_crimes = crimes[(crimes['hour'] >= 22) | (crimes['hour'] <= 3)]
# Count the frequency of night crimes per area
peak_night_crime_location = night_crimes['AREA NAME'].mode()[0] # Mode returns the most common area
print(f"The area with the largest frequency of night crimes is: {peak_night_crime_location}")
Findings:
The area with the highest frequency of night-time crimes was "Central Los Angeles", which suggests that night-time patrols and crime prevention efforts should focus on this area.
3. Victim Age Distribution
The next analysis involved categorizing victims by age groups and determining the number of crimes committed against each group. The age groups were segmented as follows: 0-17, 18-25, 26-34, 35-44, 45-54, 55-64, 65+
# Create age groups using pd.cut
age_bins = [0, 17, 25, 34, 44, 54, 64, float('inf')] # Define the bin edges
age_labels = ["0-17", "18-25", "26-34", "35-44", "45-54", "55-64", "65+"] # Define the age group labels
# Create a new column for age groups
crimes['age_group'] = pd.cut(crimes['Vict Age'], bins=age_bins, labels=age_labels, right=True)
# Count the number of crimes in each age group
victim_ages = crimes['age_group'].value_counts().sort_index()
# Print the resulting pandas Series
print(victim_ages)Findings:
The age group with the highest frequency of victims was 26-34 years, followed by the 35-44 and 45-54-year-old groups. This suggests that middle-aged adults are more frequently victims of crime, which is critical information for targeting crime prevention initiatives.