course content

Course Content

Data Manipulation using pandas

Grouping in pandas [1/2]Grouping in pandas [1/2]

To perform grouping in pandas, apply the .groupby() method to dataframe, with the column that will determine the groups passed as the parameter.

Note that grouping itself doesn't change the dataframe. Grouping always should come in pair with some aggregation.

For example, our dataframe has the 'morgh' column, representing if the dwelling is mortgaged or not (1 - Yes, 2 - No, 0 - House is being rented). Let's count number of household within each of possible groups (by applying the .size() method).

As you can see, 248 people are currently renting a house, while among 771 owners 365 have mortgages.

Everything was clear?

Section 3. Chapter 2