Loading

Quipoin Menu

Learn • Practice • Grow

python-for-ai / Grouping and Aggregation
mcq
Direction: Choose the correct option

Q1.

How do you group a DataFrame by a column?
A. df.split('col')
B. df.group('col')
C. df.groupby('col')
D. df.aggregate('col')
Direction: Choose the correct option

Q2.

After grouping, how do you get the mean of each group?
A. Both A and B
B. df.groupby('col').agg('mean')
C. df.groupby('col').aggregate(np.mean)
D. df.groupby('col').mean()
Direction: Choose the correct option

Q3.

What is the output of `df.groupby('dept')['salary'].agg(['mean','max'])`?
A. Error
B. Series with mean only
C. List of values
D. DataFrame with mean and max per dept
Direction: Choose the correct option

Q4.

How do you group by multiple columns?
A. df.groupby('col1','col2')
B. All of the above
C. df.groupby(['col1','col2'])
D. df.groupby('col1').groupby('col2')
Direction: Choose the correct option

Q5.

What does `df.groupby('col')['value'].transform('mean')` do?
A. None
B. Error
C. Returns aggregated mean
D. Broadcasts group mean to original shape
Direction: Choose the correct option

Q6.

How do you get the number of elements in each group?
A. Both A and B
B. df.groupby('col').size()
C. df.groupby('col').len()
D. df.groupby('col').count()
Direction: Choose the correct option

Q7.

What is the purpose of `pd.cut()`?
A. Cut strings
B. Duplicate data
C. Remove rows
D. Bin continuous values into intervals
Direction: Choose the correct option

Q8.

How do you apply multiple aggregation functions to different columns?
A. df.groupby('col')['col1'].mean()['col2'].sum()
B. Both A and B
C. df.groupby('col').agg({'col1':'mean', 'col2':'sum'})
D. df.groupby('col').aggregate(mean=('col1','mean'))
Direction: Choose the correct option

Q9.

What does `df.groupby('col').filter(lambda x: x['value'].sum() > 10)` do?
A. Filters rows within groups
B. Returns groups with sum >10
C. Both A and C
D. Keeps groups where condition is true
Direction: Choose the correct option

Q10.

What is the difference between `transform` and `apply` in groupby?
A. `transform` is only for aggregation
B. No difference
C. `apply` is faster
D. `transform` returns same shape; `apply` can return a scalar or Series/DataFrame