The Analytic Edge Lecture code in Python Week8 Crime

VIDEO 3 - A Basic Line Plot

Load our data:

Convert the Date variable to time format

Extract the hour and the day of the week:

Let's take a look at the structure of our data again:

Create a simple line plot - need the total number of crimes on each day of the week.

We can get this information by creating a table:

Save this table as a data frame:

Create our plot



Make the "Weekdays" variable an ORDERED

Try again:



make the x values as ordered categorical data type won't help, it is

probably due to the difference in implementation ggplot in Python.



Change our x and y labels:



VIDEO 4 - Adding the Hour of the Day

Create a counts table for the weekday and hour:

Save this to a data frame:

Get variables Hour and Weekdays

Create out plot/Change the colors

ggplot in python does not support aes(group=Var) yet

Also the ggplot version I got using pip does not seem to plot legend correctly.


Redo our plot, this time coloring by Type:


Make the lines a little transparent:


Make a heatmap:

Struggled to plot heatmap using ggplot in Python without success. Turning to the old friend matplotlib



Change the color scheme and legend label


VIDEO 5 - Maps

Given up on it...

2 thoughts on “The Analytic Edge Lecture code in Python Week8 Crime

  1. 叶飘潇雨



Leave a Reply

Your email address will not be published. Required fields are marked *