0

I have a dataframe with a huge mix of data. I want to get a count of how many times a single value occurs.

I have seen this as a way to get a count of all values: df.apply(pd.value_counts)

What I want is to get a count of just how many times that "No" appears. Not how many times each value appears, just how many times that "No" appears. So given a snapshot like below, I could get something like "The count for 'No' is 5".

Thank you!

enter image description here

EDIT: For those that flagged this as a duplicate, please read the post again. I am not trying to get a count of all the times a value appears in one column, I am looking for a count of all the times the value appears in the whole dataset, i.e. all columns. From the issue you linked, (df.education == '9th').sum() is looking at a single column, and that OP specifically asked, " I want to find the number of times something appears in a column".

Korzak
  • 365
  • 7
  • 19
  • Duplicate of https://stackoverflow.com/a/46080857 – Zero Mar 07 '18 at 15:23
  • Please read the post again. I am not trying to get a count of all the times a value appears in one column, I am looking for a count of all the times the value appears in the whole dataset, i.e. all columns. From the issue you linked, (df.education == '9th').sum() is looking at a single column, and that OP specifically asked, " I want to find the number of times something appears in a column". – Korzak Mar 07 '18 at 15:29
  • @Korzak df.stack().value_counts() – BENY Mar 07 '18 at 15:33
  • Can you actually read the post again? I am not seeking a count of ALL values in the WHOLE dataset. I want the count of ONE value in the whole dataset. – Korzak Mar 07 '18 at 15:39
  • @Wen can you please provide an idea on how to do this for ONE value for the ENTIRE dataset, not ALL values for ONE column? If not, can you remove the duplicate flags? You basically killed this post without answering it. – Korzak Mar 07 '18 at 19:15
  • @Zero can you please provide an idea on how to do this for ONE value for the ENTIRE dataset, not ALL values for ONE column? – Korzak Mar 07 '18 at 19:15
  • 1
    @Korzak (df=='No').sum().sum() – BENY Mar 07 '18 at 19:37
  • @Korzak did you really look at the method I provide before df.stack().value_counts() ? – BENY Mar 07 '18 at 19:39
  • @wen, yes, I did, and tried it even though I didn't think it would work. It gives a count of every value. – Korzak Mar 07 '18 at 19:42
  • 1
    @Korzak yes, then from that you can `s=df.stack().value_counts() ` `s.loc['No']` ? – BENY Mar 07 '18 at 19:43
  • @wen the answer you provided in your comment at 19:37 yesterday worked perfectly, thank you!!! – Korzak Mar 08 '18 at 15:44
  • 1
    @Korzak yw:-)happy coding – BENY Mar 08 '18 at 15:57

0 Answers0