All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.
All our activities include solutions with explanations on how they work and why we chose them.
First, drop the Unnamed
columns, then convert the date
column in your DataFrame to a datetime format. Next, group the data by date
and count the number of crimes that occurred each day. Create a line plot using the following parameters:
Figure size : 10 by 6
Color : Blue
Title : Daily Crime Counts
xlabel : Date
ylabel : Number of Crimes
Add a grid for clarity. Finally, display the plot. This will help you identify trends and patterns in crime rates across different months.
Begin by counting the occurrences of each crime on the crime
column, summarizing how often each type of crime appears. Then plot the graph using the following information:
Figure size : 10 by 6
Color : Red
Title : Total Number of Each Crime Type
xlabel : Crime Type
ylabel : Number of Crimes
Rotate the x-axis labels representing crime types by 45 degrees and align them to the right for better readability. Add grid lines to the y-axis using a dashed linestyle (--
) with an alpha of 0.7
for a subtle visual guide. Apply tight_layout()
to prevent any overlapping or clipping of plot elements, ensuring a clean and organized appearance. Finally, use plt.show()
to display the chart, allowing you to visually compare the frequency of different crime types in your dataset.
First, extract the day of the week from the date
column. Then, count the number of crimes that happened on each day. Then, plot this information on a graph using the following details:
Figure size : 10 by 5
Color : Coral
Edge color : Black
Title : Number of Crimes by Day of the Week
xlabel : Day of the Week
ylabel : Number of Crimes
Rotate the x-axis labels representing crime types by 45 degrees and align them to the right for better readability. Add grid lines to the y-axis using a dashed linestyle (--
) with an alpha of 0.7
for a subtle visual guide. Apply tight_layout()
to prevent any overlapping or clipping of plot elements, ensuring a clean and organized appearance. Finally, use plt.show()
to display the chart.
First, count the number of crimes in each neighborhood
and then select the top 10 neighborhoods with the most crime counts. Create a bar chart of this information. The x-axis should represent the neighborhoods and the y-axis should depict the number of crimes. Make sure you add the following details to your chart:
Figure size : 12 by 8
Color : Teal
Edge color : Black
Title : Top 10 Neighborhoods with the Most Crimes
xlabel : Neighborhood
ylabel : Number of Crimes
Finally rotate the x-axis labels for better readability(rotation=45, ha='right'), and add a dashed grid (--, alpha : 0.7
) to the y-axis to help you compare the heights of the bars easily. Apply tight_layout()
to prevent any overlapping or clipping of plot elements, ensuring a clean and organized appearance. Upon completion, you'll be able to visually analyze which neighborhoods experience the most crime.
Filter the DataFrame to include only rows with LARCENY-NON VEHICLE
and BURGLARY-RESIDENCE
. Then extract the year from the date
column and group the filtered data by year and crime type, counting the number of occurrences. Plot the resulting data on a chart, where each line represents the trend of a specific crime type over time, using the following information:
Figure size : 12 by 8
marker : o
Colors : red, blue
Title : Comparison of Crime Types Over Time
xlabel : Year
ylabel : Number of Crimes
Add a legend with the title Crime Type
, and grid lines on both axes for better readability.
Use seaborn to plot the longitude (long
) on the x-axis and latitude (lat
) on the y-axis, with different colors for each crime type, specified by the tab10
palette. Adjust the point size with the s
parameter and set the transparency with alpha to make overlapping points clearer. Add a title, x and y-axis labels, and place the legend outside the plot area for better clarity. Apply tight_layout()
to prevent any overlapping or clipping of plot elements, ensuring a clean and organized appearance. Finally, include a grid to enhance readability and use plt.show()
to display the plot. Here are the rest of the information for the plot:
Figure size : 12 by 8
Color palette : tab10
Hue : crime
s = 15
Alpha : 0.7
Title : Crime Locations in Atlanta by Crime Type
xlabel : Longitude
ylabel : Latitude
Legend
Title : Crime Type
bbox_to_anchor : 1.05, 1
loc : upper left
In this task, you will use the Pandas .plot()
method to create a stacked bar chart to visualize the number of crimes committed in each Neighborhood Planning Unit (NPU), classified by crime type. Begin by grouping the data by NPU
and crime
. Count the occurrences and reshape the data into a DataFrame. Now, plot this data employing the details below:
Figure size : 14 by 8
Colormap : tab20
Bar width :0.90
Title : Number of Crimes in Each NPU, Broken Down by Crime Type
xlabel : Neighborhood Planning Unit (NPU)
ylabel : Number of Crimes
Legend
Title : Crime Type
bbox_to_anchor : 1.05,1
Loc : upper left
Add a dashed grid(--, alpha : 0.7
) to the y-axis to help you compare the heights of the bars easily. Also, apply tight_layout()
to prevent any overlapping or clipping of plot elements.
Count the occurrences of each crime type, then generate a pie chart with labels, percentages, and a color scheme, title, and a circular shape, using the following details:
Figure size : 10 by 10
autopct :%1.1f%%
Startangle : 140
Colors : plt.cm.tab20.colors
Title : Distribution of Crime Types
This provides a visual representation of the relative prevalence of different crime types in the data. Also, apply tight_layout()
to prevent any overlapping or clipping of plot elements, ensuring a clean and organized appearance.
First, filter the dataset to include only BURGLARY-RESIDENCE
incidents, then create two subsets: one for the summer months (June, July, and August) and another for the rest of the year. Next, count the number of burglaries in each subset. Finally, generate a bar chart to visually compare the number of burglaries during summer versus other months. Use the following details to plot the graph:
Figure size : 10 by 10
Colors : Orange and blue
Title : Number of Burglaries in Summer vs Other Months
y-label : Number of Burglaries
x-coordinates of bars: ['Summer Months', 'Other Months']
Start by focusing on only the specified robbery types: ['ROBBERY-PEDESTRIAN','ROBBERY-COMMERCIAL','ROBBERY-RESIDENCE']. Your task is to group this data by year and by robbery type, count the instances, and create a line plot to illustrate how each robbery type's frequency has changed over the years. Use the following parameters:
Figure size : 12 by 8
Title : Robbery Types Over Time
y-label : Number of Crimes
x-label : Year
The plot should also include annotations to display the exact number of incidents for each data point.
Annotations
xytext : 0,10
ha : center
textcoords : offset points
First count the number of occurrences of each robbery type, then creates a pie chart where each slice represents the percentage of each type relative to the total.
Figure size : 6 by 6
autopct : %1.1f%%
Colors : skyblue, lightgreen and lightcoral
Title : Proportion of Robbery Types
Apply tight_layout()
to prevent any overlapping or clipping of plot elements, ensuring a clean and organized appearance.