BaşlayınÜcretsiz Başlayın

Calculating the hourly arrest rate

When a police officer stops a driver, a small percentage of those stops ends in an arrest. This is known as the arrest rate. In this exercise, you'll find out whether the arrest rate varies by time of day.

First, you'll calculate the arrest rate across all stops in the ri DataFrame. Then, you'll calculate the hourly arrest rate by using the hour attribute of the index. The hour ranges from 0 to 23, in which:

  • 0 = midnight
  • 12 = noon
  • 23 = 11 PM

Bu egzersiz

Analyzing Police Activity with pandas

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Take the mean of the is_arrested column to calculate the overall arrest rate.
  • Group by the hour attribute of the DataFrame index to calculate the hourly arrest rate.
  • Save the hourly arrest rate Series as a new object, hourly_arrest_rate.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Calculate the overall arrest rate
print(____)

# Calculate the hourly arrest rate
print(ri.groupby(____).____)

# Save the hourly arrest rate
hourly_arrest_rate = ____
Kodu Düzenle ve Çalıştır