-1

I'm brand new to pandas and I have a csv file which i have read in with csv_read with pandas eg. I have read it in as 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?

Kerjifire
  • 51
  • 1
  • 7
  • Sorry are you asking for `df.loc[df['ID']=='D','Gender'].value_counts()`? – EdChum Apr 22 '16 at 12:27
  • @ Kerjifire, welcome to stackoverflow. I think this is a duplicate question, see similar question [here](http://stackoverflow.com/questions/20995196/python-pandas-counting-and-summing-specific-conditions) – Manohar Swamynathan Apr 22 '16 at 12:40
  • yeah I want the data to show that M has 2 occurrences and F has 2 in this example – Kerjifire Apr 22 '16 at 12:41
  • This is really more a dupe of this: http://stackoverflow.com/questions/22391433/count-the-frequency-that-a-value-occurs-in-a-dataframe-column/22391554#22391554 but with a filter criteria – EdChum Apr 22 '16 at 12:45

1 Answers1

0

Try this:

b['tmp'] = 1
b.groupby(['Gender', 'ID']).count().query('ID == "D"')
Shovalt
  • 6,407
  • 2
  • 36
  • 51