Question:

Which of the following functions are used to split the data into groups based on some criteria?

Show Hint

Splitting data into groups by a key is done with groupby(), the pandas version of SQL GROUP BY.
Updated On: Oct 1, 2026
  • split()
  • GROUP BY()
  • first()
  • reset_index()
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understanding the Concept:
In pandas, data is split into groups by a key using the groupby() method. This follows the split-apply-combine idea. First the data is split into groups, then a function such as sum or mean is applied to each group, and last the results are combined. Among the four options, the one that stands for the grouping function is GROUP BY().

Step 2: Check option 1 (split()).
split() is a string method. It breaks a string into a list at a separator. It does not group DataFrame rows. So option 1 is wrong.

Step 3: Check option 2 (GROUP BY()).
This is the grouping function. The grouping idea is the same as the SQL clause GROUP BY, and the pandas method is written groupby(). Of all the options, only this one is meant to group data by some criteria. So option 2 is correct.

Step 4: Check option 3 (first()).
first() returns the first entry in each group once a grouping already exists. It does not split the data. So option 3 is wrong.

Step 5: Check option 4 (reset_index()).
reset_index() turns the index back into normal numbering or a column. It is often used after grouping, but it does not group. So option 4 is wrong.

Step 6: Final Answer:
The function that groups data by a criterion is GROUP BY(), which is option 2. The exact pandas spelling is groupby(). \[ \boxed{\text{GROUP BY()}} \]
Was this answer helpful?
0
0