pandas groupby
import pandas as pd
path = 'https://raw.githubusercontent.com/HoijanLai/dataset/master/PoliceKillingsUS.csv'
data = pd.read_csv(path,index_col=None)
data.head()
`` name date race age signs_of_mental_illness flee
0 Tim Elliot 02/01/15 A 53.0 True Not fleeing
1 Lewis Lee Lembke 02/01/15 W 47.0 False Not fleeing
2 John Paul Quintero 03/01/15 H 23.0 False Not fleeing
3 Matthew Hoffman 04/01/15 W 32.0 True Not fleeing
4 Michael Rodriguez 04/01/15 H 39.0 False Not fleeing
###
data['race'].value_counts()
W 1201
B 618
H 423
A 39
N 31
O 28
###
data.groupby('race')['age'].mean()
race
A 36.605263
B 31.635468
H 32.995157
N 30.451613
O 33.071429
W 40.046980
###
data['signs_of_mental_illness'].value_counts()
False 1902
True 633
###
data.groupby('race')['signs_of_mental_illness'].value_counts()
race signs_of_mental_illness
A False 29
True 10
B False 523
True 95
H False 338
True 85
N False 23
True 8
O False 21
True 7
W False 819
True 382
data.groupby('race'['signs_of_mental_illness'].value_counts().unstack()
signs_of_mental_illness False True
race
A 29 10
B 523 95
H 338 85
N 23 8
O 21 7
W 819 382
###
data.groupby('race')['flee'].value_counts().unstack()
flee Car Foot Not fleeing Other
race
A 4.0 5.0 28.0 NaN
B 90.0 113.0 379.0 23.0
H 74.0 50.0 268.0 19.0
N 2.0 6.0 21.0 NaN
O 4.0 2.0 21.0 1.0
W 191.0 103.0 838.0 46.0
###
data.groupby('race'['flee'].value_counts().unstack().plot(kind='bar',figsize=(20,5))
https://img-blog.csdnimg.cn/20191121093253192.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzIxODQwMjAx,size_16,color_FFFFFF,t_70
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
형태소 분석은 데스크톱을 구성하는 데 도움이?문자×기계 학습에 흥미를 가져와 개인 범위의 용도를 생각해, 폴더 정리에 사용할 수 있을까 생각해 검토를 시작했습니다. 이번 검토에서는 폴더 구성 & text의 읽기 → mecab × wordcloud를 실시하고 있...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.