Complete the code to group the DataFrame by 'Category'.
grouped = df.groupby([1])The groupby function groups data by the specified column. Here, we want to group by the 'Category' column.
Complete the code to apply a custom function that calculates the range (max - min) of 'Value' in each group.
def range_func(x): return x.max() - [1] result = df.groupby('Category')['Value'].apply(range_func)
The range is calculated as the maximum value minus the minimum value in each group.
Fix the error in the custom function to correctly calculate the mean of 'Value' after grouping.
def mean_func(x): return x.[1]() result = df.groupby('Category')['Value'].apply(mean_func)
The function should use mean() to calculate the average value in each group.
Fill both blanks to create a dictionary comprehension that maps each group to the count of 'Value' greater than 10.
counts = {group: sum(df.loc[df['Category'] == group, 'Value'] [1] 10) for group in df['Category'].unique() if sum(df.loc[df['Category'] == group, 'Value'] [2] 10) > 0}The code counts how many 'Value' entries are greater than 10 in each group. Both blanks use the '>' operator.
Fill all three blanks to create a dictionary comprehension that maps each group to the average 'Value' for values greater than 5.
averages = {group: df.loc[(df['Category'] == group) & (df['Value'] [1] 5), [2]].[3]() for group in df['Category'].unique()}The code filters 'Value' greater than 5, selects the 'Value' column, and calculates the mean for each group.