開始使用免費開始

計算保護性搜身次數

在搜查車輛時,警方可能會先對駕駛進行拍搜,以確認是否攜帶武器。這稱為「保護性搜身」。

在這個練習中,你會先檢查「Protective Frisk」是否曾作為唯一的搜查類型,並計算其次數。接著,你會使用字串方法找出所有對駕駛進行搜身的情況。

本練習屬於課程

使用 pandas 分析警方執法活動

檢視課程

練習說明

  • risearch_type 欄位進行計數,查看「Protective Frisk」作為唯一搜查類型出現了多少次。
  • 建立新欄位 frisk,當 search_type 包含字串「Protective Frisk」時為 True,否則為 False
  • 檢查 frisk 的資料型別,確認它是布林 Series。
  • frisk 取總和,以計算搜身的總次數。

動手互動練習

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

# Count the 'search_type' values
print(____)

# Check if 'search_type' contains the string 'Protective Frisk'
ri['frisk'] = ri.search_type.str.contains('____', na=____)

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

# Take the sum of 'frisk'
print(____)
編輯並執行程式碼