Query dataframe and filter column values and return count

时间:2018-11-27 21:41:02

标签: python pandas dataframe

I've have the following 2 columns in my df:

      vict_age        vict_sex
0       22.0               M
1       39.0               F
2       33.0               M
3       17.0  Unknown Gender
4       51.0               M
5       52.0               F
7       17.0  Unknown Gender
8       63.0               M
9       50.0               M
10      14.0               F
11      33.0               M 
12      36.0               F
13      50.0               F
14      34.0               M
15      29.0               F

I would like to get a count where vict_sex = M and vict_age < 40 for e.g.

using the query function allowed me to return this:

 df3.query("vict_sex=='M'")['vict_age']


      vict_age
0     22.0
2     33.0
4     51.0
8     63.0
9     50.0
11    33.0
14    34.0

how can I get a count of vict_age < 40?

Name: vict_age, dtype: float64

0 个答案:

没有答案