開始使用免費開始

計算搜尋率

在交通攔查中,員警有時會對車輛進行搜尋。在本練習中,你要計算 ri DataFrame 中所有攔查事件中,導致車輛被搜尋的百分比,也就是所謂的搜尋率。

本練習屬於課程

使用 pandas 分析警方執法活動

檢視課程

練習說明

  • 檢查 search_conducted 的資料型別,確認它是 Boolean Series。
  • 透過計數 Series 的值並將其表示為比例,來計算搜尋率。
  • 透過取該 Series 的平均值來計算搜尋率。(結果應該與上面計算的 True 值比例相符。)

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Check the data type of 'search_conducted'
print(____)

# Calculate the search rate by counting the values
print(____)

# Calculate the search rate by taking the mean
print(____)
編輯並執行程式碼