Pandas groupby to count the number of instances

Question:

How to group my dataframe dataset by the column default using Pandas?

From the cheat sheet:

enter image description here

An this is my code:

dataset.groupby(by = "default")

Which returns:

<pandas.core.groupby.generic.DataFrameGroupBy object at 0x7fb4ac4f2490>
Asked By: unstuck

||

Answers:

It seens you question is a little on the theoretical side, so I am going to explain to you how to do what you want and also what @It_is_Chris, meant on his comment.

So how does groupby work in Pandas?

A: The idea is pretty simple, imagine you are grouping by one column with two different values. Python will create "small data frames" filtered accordingly to the column being grouped. Such generated "small data frames" come out as groupby generator Objects, which to be honest is outside the given subject. But just think of them as "small separated data frames with each one having a given set of characteristics/attributes".

Now about your question, didnt quite catch what you want but I guess is just the amount of events, or the size of the dataframe. Nonetheless, just take a look at the pandas docs and you will be able to find out which method fits better

dataset.groupby(by = "default").count()
Answered By: INGl0R1AM0R1
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.