|
--- |
|
datasets: |
|
- hj |
|
language: |
|
- en |
|
license: bsd |
|
tags: |
|
- crime |
|
- homicide |
|
--- |
|
# 2025 Homicide Trend Analysis |
|
|
|
 |
|
 |
|
 |
|
|
|
π This project provides Python-based data visualization examples for analyzing homicide trends over time. |
|
|
|
Source: [HeyJackass.com](https://heyjackass.com ) |
|
|
|
--- |
|
|
|
## π Overview |
|
|
|
This repository includes Python scripts to visualize homicide data using: |
|
- Bar graphs |
|
- Pie charts |
|
- DataFrames from `pandas` |
|
|
|
All visualizations are based on real-world data spanning from **2015 to 2024**. |
|
|
|
--- |
|
|
|
## π Sample Data |
|
|
|
| Year | Homicides | |
|
|------|-----------| |
|
| 2024 | 219 | |
|
| 2023 | 257 | |
|
| 2022 | 261 | |
|
| 2021 | 276 | |
|
| 2020 | 254 | |
|
| 2019 | 211 | |
|
| 2018 | 211 | |
|
| 2017 | 257 | |
|
| 2016 | 262 | |
|
| 2015 | 174 | |
|
|
|
--- |
|
|
|
## π Visualization Examples |
|
|
|
### 1. Bar Graph: Homicides Per Year |
|
|
|
```python |
|
import matplotlib.pyplot as plt |
|
import pandas as pd |
|
|
|
# Data from your CSV |
|
data = { |
|
'Year': [2024, 2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015], |
|
'Homicides': [219, 257, 261, 276, 254, 211, 211, 257, 262, 174] |
|
} |
|
|
|
# Convert to DataFrame |
|
df = pd.DataFrame(data) |
|
|
|
# Plot bar graph |
|
plt.figure(figsize=(10, 6)) |
|
plt.bar(df['Year'].astype(str), df['Homicides'], color='skyblue') |
|
plt.title('Homicides Per Year') |
|
plt.xlabel('Year') |
|
plt.ylabel('Number of Homicides') |
|
plt.xticks(rotation=45) |
|
plt.tight_layout() |
|
|
|
# Show the plot |
|
plt.show() |
|
``` |
|
### 2. Pie Chart: Distribution of Incidents by Year |
|
```python |
|
from datasets import load_dataset |
|
import matplotlib.pyplot as plt |
|
|
|
# Load the dataset |
|
ds = load_dataset("ajsbsd/hj") |
|
|
|
# Count year occurrences |
|
year_counts = {} |
|
for entry in ds['train']: |
|
year = entry.get('Year', None) |
|
if year is not None: |
|
year_counts[year] = year_counts.get(year, 0) + 1 |
|
|
|
# Sort years |
|
sorted_years = sorted(year_counts.items()) |
|
years, counts = zip(*sorted_years) |
|
|
|
# Plot pie chart |
|
plt.figure(figsize=(8, 8)) |
|
plt.pie(counts, labels=years, autopct='%1.1f%%', startangle=140) |
|
plt.title('Distribution of Incidents by Year') |
|
plt.axis('equal') |
|
plt.show() |
|
``` |
|
|
|
BSD-3-Clause-Clear License |
|
|
|
See LICENSE file for full text. |