Search this site
Embedded Files
AIMD GPDS Courses
  • Home
  • Courses
  • Contact
AIMD GPDS Courses
  • Home
  • Courses
  • Contact
  • More
    • Home
    • Courses
    • Contact

日本語  ❯

Lesson 2    ❮    Lesson List    ❮    Top Page

2.1  Filtering with Boolean

❯  2.2  Grouping Object

2.3  Aggregation

2.4  Concatenate, Join, Merge

⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
EXPECTED COMPLETION TIME
❲▹❳  Video   6m 31s
☷  Interactive readings   5m

Making a GroupBy object

We will create a pandas DataFrame groupby object using the pandas DataFrame groupby method, passing it a column or list of columns for the grouping. In the movie dataset, we will try to do grouping by 'director_name'.

> Note that groupby object cannot be printed right away.

Capturing a Particular Group

We can use get_group to get all the rows for a particular group. Say, we want to get the data about the director 'Steven Spielberg'.  The get_group method will show all the rows containing that director.

To show the number of rows for each director, we can use the method size.

Capturing First/Last Occurence of Group

We can also use first and last method of the groupby object to create DataFrames with the first and last occurrence of each group.

Capturing Criteria of Multiple Group

GroupBy object is not limited to one column name. We can put in a list and select a particular group for each element in that list.

©2023. All rights reserved.  Samy Baladram,
Graduate Program in Data Science - GSIS - Tohoku University
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse