ajsbsd commited on
Commit
28870a0
Β·
verified Β·
1 Parent(s): 73d3b4c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -40
README.md CHANGED
@@ -1,7 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
- license: bsd-3-clause-clear
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
4
- Source: [Source: HeyJackass.com](https:///heyjackass.com)
 
 
 
 
 
5
  import matplotlib.pyplot as plt
6
  import pandas as pd
7
 
@@ -25,63 +66,34 @@ plt.tight_layout()
25
 
26
  # Show the plot
27
  plt.show()
28
-
29
- # Python3 Examples for Bar/Pie Chart
30
- ### πŸ“Š Python Code to Create a Pie Chart Based on Year Distribution
31
-
32
- ``python
33
-
34
  from datasets import load_dataset
35
  import matplotlib.pyplot as plt
36
 
37
  # Load the dataset
38
  ds = load_dataset("ajsbsd/hj")
39
 
40
- # Assuming the dataset is in the 'train' split and contains a 'Year' column
41
  year_counts = {}
42
-
43
- # Count occurrences per year
44
  for entry in ds['train']:
45
  year = entry.get('Year', None)
46
  if year is not None:
47
  year_counts[year] = year_counts.get(year, 0) + 1
48
 
49
- # Sort by year for consistent ordering
50
  sorted_years = sorted(year_counts.items())
51
-
52
  years, counts = zip(*sorted_years)
53
 
54
  # Plot pie chart
55
  plt.figure(figsize=(8, 8))
56
  plt.pie(counts, labels=years, autopct='%1.1f%%', startangle=140)
57
  plt.title('Distribution of Incidents by Year')
58
- plt.axis('equal') # Equal aspect ratio ensures the pie is circular
59
  plt.show()
 
60
 
61
- ### πŸ“Š Python Code to Create a Bar Graph of Homicides Per Year
62
-
63
- import matplotlib.pyplot as plt
64
- import pandas as pd
65
-
66
- # Data from your CSV
67
- data = {
68
- 'Year': [2024, 2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015],
69
- 'Homicides': [219, 257, 261, 276, 254, 211, 211, 257, 262, 174]
70
- }
71
-
72
- # Convert to DataFrame
73
- df = pd.DataFrame(data)
74
-
75
- # Plot bar graph
76
- plt.figure(figsize=(10, 6))
77
- plt.bar(df['Year'].astype(str), df['Homicides'], color='skyblue')
78
- plt.title('Homicides Per Year')
79
- plt.xlabel('Year')
80
- plt.ylabel('Number of Homicides')
81
- plt.xticks(rotation=45)
82
- plt.tight_layout()
83
-
84
- # Show the plot
85
- plt.show()
86
 
87
- ```
 
1
+ # 2025 Homicide Trend Analysis
2
+
3
+ ![License](https://img.shields.io/badge/license-BSD--3--Clause--Clear-blue )
4
+ ![Python](https://img.shields.io/badge/python-3.8+-blue.svg )
5
+ ![Platform](https://img.shields.io/badge/platform-linux%20%7C%20macos%20%7C%20windows-lightgrey )
6
+
7
+ πŸ“Š This project provides Python-based data visualization examples for analyzing homicide trends over time.
8
+
9
+ Source: [HeyJackass.com](https://heyjackass.com )
10
+
11
+ ---
12
+
13
+ ## πŸ“Š Overview
14
+
15
+ This repository includes Python scripts to visualize homicide data using:
16
+ - Bar graphs
17
+ - Pie charts
18
+ - DataFrames from `pandas`
19
+
20
+ All visualizations are based on real-world data spanning from **2015 to 2024**.
21
+
22
  ---
23
+
24
+ ## πŸ“ˆ Sample Data
25
+
26
+ | Year | Homicides |
27
+ |------|-----------|
28
+ | 2024 | 219 |
29
+ | 2023 | 257 |
30
+ | 2022 | 261 |
31
+ | 2021 | 276 |
32
+ | 2020 | 254 |
33
+ | 2019 | 211 |
34
+ | 2018 | 211 |
35
+ | 2017 | 257 |
36
+ | 2016 | 262 |
37
+ | 2015 | 174 |
38
+
39
  ---
40
+
41
+ ## πŸ“Š Visualization Examples
42
+
43
+ ### 1. Bar Graph: Homicides Per Year
44
+
45
+ ```python
46
  import matplotlib.pyplot as plt
47
  import pandas as pd
48
 
 
66
 
67
  # Show the plot
68
  plt.show()
69
+ ```
70
+ ### 2. Pie Chart: Distribution of Incidents by Year
71
+ ```python
 
 
 
72
  from datasets import load_dataset
73
  import matplotlib.pyplot as plt
74
 
75
  # Load the dataset
76
  ds = load_dataset("ajsbsd/hj")
77
 
78
+ # Count year occurrences
79
  year_counts = {}
 
 
80
  for entry in ds['train']:
81
  year = entry.get('Year', None)
82
  if year is not None:
83
  year_counts[year] = year_counts.get(year, 0) + 1
84
 
85
+ # Sort years
86
  sorted_years = sorted(year_counts.items())
 
87
  years, counts = zip(*sorted_years)
88
 
89
  # Plot pie chart
90
  plt.figure(figsize=(8, 8))
91
  plt.pie(counts, labels=years, autopct='%1.1f%%', startangle=140)
92
  plt.title('Distribution of Incidents by Year')
93
+ plt.axis('equal')
94
  plt.show()
95
+ ```
96
 
97
+ BSD-3-Clause-Clear License
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
+ See LICENSE file for full text.