以性別比較超速攔查結果
當駕駛因超速被攔查時,很多人認為性別會影響是否收到罰單或警告。你能在這個資料集中找到相關證據嗎?
首先,你會建立兩個因超速而被攔查的 DataFrame:一個包含女性駕駛,另一個包含男性駕駛。
接著,對每個性別,使用 stop_outcome 欄位計算有多少比例的攔查結果是「Citation」(也就是罰單)與「Warning」(警告)。
本練習屬於課程
使用 pandas 分析警方執法活動
練習說明
- 建立只包含因超速被攔查之女性駕駛的 DataFrame,命名為
female_and_speeding。 - 建立只包含因超速被攔查之男性駕駛的 DataFrame,命名為
male_and_speeding。 - 對女性駕駛計算攔查結果的次數,並以比例表示。
- 對男性駕駛計算攔查結果的次數,並以比例表示。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a DataFrame of female drivers stopped for speeding
female_and_speeding = ri[____]
# Create a DataFrame of male drivers stopped for speeding
male_and_speeding = ri[____]
# Compute the stop outcomes for female drivers (as proportions)
print(female_and_speeding.____)
# Compute the stop outcomes for male drivers (as proportions)
print(male_and_speeding.____)