Session Ready
Exercise

Find the Months with the Highest Number of Crimes

Using the crime_data list from the prior exercise, you'll answer a common question that arises when dealing with crime data: How many crimes are committed each month?

Feel free to use the IPython Shell to explore the crime_data list - it has been pre-loaded for you. For example, crime_data[0][0] will show you the first column of the first row which, in this case, is the date and time time that the crime occurred.

Instructions
100 XP
  • Import Counter from collections and datetime from datetime.
  • Create a Counter object called crimes_by_month.
  • Loop over the crime_data list:
    • Using the datetime.strptime() function, convert the first element of each item into a Python Datetime Object called date.
    • Increment the counter for the month associated with this row by one. You can access the month of date using date.month.
  • Print the 3 most common months for crime.