Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Looping through Pandas Dataframe Columns to count values

I have a column with 14000+ rows and there is only two numbers in this column.

for i  in df['Yes/No']:
  
  if(i in "Yes"):
    y_counter += 1

  else:
    n_counter += 1

When I try this I get an equal 12/12 return for each counter. That is definitely not correct. How do I loop through and count the Yes and Nos?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can do it like this :

y_counter = (data['Yes/No'] == 'yes').sum()
n_counter = (data['Yes/No'] == 'no').sum()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading