简体   繁体   中英

Count number of dataframe entries with certain value using python pandas

In my pandas Dataframe i want to access the status column and count the number of times the value Fail appears. I am trying to implement a groupby method in order to see the number of fails but i am getting a weird output in the picture:

total = df.groupby("status").sum()

H

In [38]: df = pd.DataFrame(["Fail","OK"] * 9, columns=["status"])

In [39]: df["status"].value_counts()
Out[39]:
OK      9
Fail    9
Name: status, dtype: int64

Use value_counts() to get the count of occurrence

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM