Crime Analyzer and Map Visualizer is a Python code that provides a tool for analyzing and visualizing crime data. This code utilizes popular libraries such as pandas, matplotlib, calendar, and folium to process and visualize the data.
- Data Retrieval: The code includes a function to download a CSV file containing crime data from a specified URL and save it locally.
- Data Processing: The code reads the downloaded CSV file, cleans the data by removing irrelevant entries, and performs necessary data transformations.
- Data Analysis: Several analysis functions are implemented to provide insights into crime frequency, temporal patterns, victim demographics, crime status, premise and weapon distribution, and crime versus age relationships.
- Map Visualization: The code utilizes the folium library to plot crime locations on an interactive map using latitude and longitude coordinates.
- Data Visualization: The code includes functions to create various visualizations such as bar charts, histograms, and pie charts to present the analyzed crime data.
- Install the required dependencies.
- Instantiate the
CrimeAnalyzer
class with the URL of the crime data CSV file and the desired path to save the downloaded file. - Call the
process_data()
method of theCrimeAnalyzer
instance to download the CSV file, read and clean the data, perform data analysis, and generate visualizations. - The analysis results will be printed to the console, and visualizations will be displayed using matplotlib and folium.
from CrimeAnalyzer import CrimeAnalyzer
# Instantiate the CrimeAnalyzer class and process the data
url = 'https://data.lacity.org/api/views/2nrs-mtv8/rows.csv?accessType=DOWNLOAD'
path = 'data/crimes.csv'
report_path = 'data/crime_report.txt'
analyzer = CrimeAnalyzer(url, path, report_path)
analyzer.process_data()
The code requires the following dependencies:
- pandas
- matplotlib
- calendar
- folium
This code is licensed under the MIT License.