0

I have the following dataframe:

id expNumber attempt finished successful
1 1 1 true false
1 1 2 false false
1 1 3 true true
1 2 1 false false
1 2 2 true false
1 2 3 true true
1 4 1 false false
1 4 2 false false
id,expNumber,attempt,finished,successful,
1,1,1,true,false,
1,1,2,false,false,
1,1,3,true,true,
1,2,1,false,false,
1,2,2,true,false,
1,2,3,true,true,
1,4,1,false,false,
1,4,2,false,false,

And I want to create a dataframe which counts the data grouped by the value of the column. Here is what I expect:

true 4
false 4

I tried the following code but when I print the result, its just empty.

df = df.groupby('finished'.sum())
print("test", df)

2 Answers 2

1

Select columns for count and use value_counts:

df = df[['finished','successful']].apply(pd.value_counts)
print("test", df)
test        finished  successful
False         4           6
True          4           2
Sign up to request clarification or add additional context in comments.

Comments

1

You can do either of the following:

df.groupby("finished").count()

Or:

df["finished"].value_counts()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.