0

Using the PANDAS, I want to arrive at the preference of two different groups. eg: Male and Female client visiting the hospital from a CSV file.

I have arrived at the counts by group by. I'm stuck at the below two scenarios:

  1. If I need to filter only by male or female and the count by the hospital.
  2. If I need to remove particular row values (exclude a particular hospital)

Coding part

import pandas as pd 
enter code here`df = pd.read_csv("EDdata.csv", index_col = "Case")
df.groupby(['Hospital_Name','Gender'])['Gender'].count()

Result:

Hospital_Name  Gender    Count

AH             F          667
               M         1433

CGH            F         2763
               M         4301

KKH            F         3466
               M         4431

KTPH           F         2116
               M         3886
kgangadhar
  • 4,886
  • 5
  • 36
  • 54
  • Does this help you answer the question - [example1](https://stackoverflow.com/questions/39634175/pandas-groupby-with-condition/39634269), [example2](https://stackoverflow.com/questions/50662469/pandas-group-by-a-column-that-meets-a-condition), [example3](https://stackoverflow.com/questions/45083000/pandas-groupby-with-conditional-formula) – Joe Ferndz Sep 02 '20 at 02:43
  • Welcome to Stack Overflow. Please read how to ask good [questions](https://stackoverflow.com/help/how-to-ask). Make sure your question covers these 3 elements: 1. Problem Statement 2. Your Code (it should be [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) 3. Error Message (preferably full Traceback to help others review and provide feedback). Sometimes the same question may have already been asked. Make sure your question is not a [duplicate](https://stackoverflow.com/help/duplicates) – Joe Ferndz Sep 02 '20 at 02:44

0 Answers0