kitchen800
kitchen800

Reputation: 227

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

Upvotes: 1

Views: 32

Answers (1)

bigbounty
bigbounty

Reputation: 17368

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

Upvotes: 2

Related Questions