8

I have Data Frame, which contains 2 columns: age and gender.

sex,age
1,30
2,29
1,34
1,27
2,28
2,28
1,40
1,30
1,27
2,31
1,37
1,31
2,28
2,30
2,27
2,27
2,29
2,32
1,28
1,27
1,28
1,28
1,29
1,33
1,32
1,30

How can I plot age distribution for each gender?

4

1 回答 1

18

groupby然后plotkind='kde'

df1.groupby('sex').age.plot(kind='kde')

在此处输入图像描述

每@EdChum

df1.groupby('sex').age.hist()

在此处输入图像描述

于 2016-07-01T14:29:55.760 回答