開始使用免費開始

比較不同性別的搜身率

在這個練習中,你要比較在搜查過程中,女性與男性駕駛被搜身的比例。男性是否比女性更常被搜身?或許是因為員警認為他們的風險較高?

在進行任何計算之前,請先將 DataFrame 篩選為只包含相關的資料子集,也就是實際有進行搜查的攔查紀錄。

本練習屬於課程

使用 pandas 分析警方執法活動

檢視課程

練習說明

  • 建立一個 DataFrame searched,只包含 search_conductedTrue 的列。
  • frisk 欄位取平均,找出有包含搜身的搜查所佔的百分比。
  • 使用 .groupby() 計算各性別的搜身率。

動手互動練習

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

# Create a DataFrame of stops in which a search was conducted
searched = ri[ri.____ == ____]

# Calculate the overall frisk rate by taking the mean of 'frisk'
print(searched.____)

# Calculate the frisk rate for each gender
print(searched.____)
編輯並執行程式碼