Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot age distribution with pandas

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?

like image 387
Dmitrijs Zubriks Avatar asked Jul 01 '16 12:07

Dmitrijs Zubriks


1 Answers

groupby then plot with kind='kde'

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

enter image description here

Per @EdChum

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

enter image description here

like image 108
piRSquared Avatar answered Nov 16 '22 05:11

piRSquared