เพศมีผลต่อประเภทการละเมิดหรือไม่?

การวิเคราะห์กิจกรรมตำรวจด้วย pandas

Kevin Markham

Founder, Data School

การนับค่าที่ไม่ซ้ำกัน (1)

  • .value_counts(): นับค่าที่ไม่ซ้ำกันใน Series
  • เหมาะกับข้อมูลเชิงหมวดหมู่
ri.stop_outcome.value_counts()
Citation            77091
Warning              5136
Arrest Driver        2735
No Action             624
N/D                   607
Arrest Passenger      343
Name: stop_outcome, dtype: int64
การวิเคราะห์กิจกรรมตำรวจด้วย pandas

การนับค่าที่ไม่ซ้ำกัน (2)

ri.stop_outcome.value_counts().sum()
86536
ri.shape
(86536, 13)
การวิเคราะห์กิจกรรมตำรวจด้วย pandas

แสดงจำนวนนับเป็นสัดส่วน

ri.stop_outcome.value_counts()
77091/86536
0.8908546731995932
Citation            77091
Warning              5136
Arrest Driver        2735
No Action             624
N/D                   607
Arrest Passenger      343
ri.stop_outcome.value_counts(
  normalize=True)
Citation            0.890855
Warning             0.059351
Arrest Driver       0.031605
No Action           0.007211
N/D                 0.007014
Arrest Passenger    0.003964
การวิเคราะห์กิจกรรมตำรวจด้วย pandas

การกรองแถวใน DataFrame

ri.driver_race.value_counts()
White       61870
Black       12285
Hispanic     9727
Asian        2389
Other         265
white = ri[ri.driver_race == 'White']

white.shape
(61870, 13)
การวิเคราะห์กิจกรรมตำรวจด้วย pandas

เปรียบเทียบผลลัพธ์การหยุดรถระหว่างสองกลุ่ม

white.stop_outcome.value_counts(
  normalize=True)
Citation            0.902263
Warning             0.057508
Arrest Driver       0.024018
No Action           0.007031
N/D                 0.006433
Arrest Passenger    0.002748
asian = ri[ri.driver_race ==
           'Asian']

asian.stop_outcome.value_counts( normalize=True)
Citation            0.922980
Warning             0.045207
Arrest Driver       0.017581
No Action           0.008372
N/D                 0.004186
Arrest Passenger    0.001674
การวิเคราะห์กิจกรรมตำรวจด้วย pandas

มาฝึกกันเถอะ!

การวิเคราะห์กิจกรรมตำรวจด้วย pandas

Preparing Video For Download...