简体   繁体   English

给定另一列包含特定值的 Pandas 行数

[英]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.

相关问题 pandas:如果列包含特定值,则重复一行 - pandas: repeat a row if a column contains certain value Pandas Dataframe:对于给定的行,尝试基于在另一列中查找值来分配特定列中的值 - Pandas Dataframe: for a given row, trying to assign value in a certain column based on a lookup of a value in another column 计算列在Pandas中包含特定值的次数 - Count how many times a column contains a certain value in Pandas 熊猫计算列中的某些值 - Pandas Count certain Value in a column 计算另一列是否包含值 - Count if another column contains a value 删除一行,如果它包含熊猫中的某个值 - Drop a row if it contains a certain value in pandas 如果任何列包含所述行中的某个值,则在Pandas Dataframe中删除一行 - Drop a row in a Pandas Dataframe if any column contains a certain value, in said row Pandas:如果下一列的行包含特定值,则按列号划分列数据 - Pandas: Divide column data by number if row of next column contains certain value 熊猫:如何通过特定列值的值获取行计数,以及如何将计数添加为另一列。 - Pandas: How to get a row count by the value of a particular column value, and add the count as another column. 如果另一列包含给定列的名称,则更改给定列的值 - Change value of a given column if another column contains the name of the given column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM