[英]Pandas row count given another column contains a certain value
I'm brand new to pandas and I have a csv file which i have read in with csv_read with pandas eg.我是 Pandas 的新手,我有一个 csv 文件,我用 csv_read 读入了 Pandas,例如。 I have read it in as b = pandas.read_csv('BLA.csv')我已将其阅读为 b = pandas.read_csv('BLA.csv')
| Gender | ID |
| M | D |
| F | P |
| M | P |
| F | D |
| M | D |
| F | D |
how do I go about counting the number of occurrences of the Genders given the ID status of the person is D?鉴于此人的 ID 状态为 D,我该如何计算性别出现的次数?
Try this:尝试这个:
b['tmp'] = 1
b.groupby(['Gender', 'ID']).count().query('ID == "D"')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.