Complete the code to group the DataFrame by the 'category' column.
grouped_df = df.[1]('category')
The groupBy method groups the DataFrame rows by the specified column.
Complete the code to calculate the average of the 'sales' column after grouping.
result = df.groupBy('category').[1]('sales')
The avg function calculates the average value of the specified column for each group.
Fix the error in the code to sum the 'quantity' column after grouping by 'product'.
total_quantity = df.groupBy('product').[1]('quantity')
The correct aggregation function to sum values is sum. Other options are invalid method names.
Fill both blanks to create a dictionary for aggregation: count 'id' and max 'price'.
agg_result = df.groupBy('store').agg([1]: 'count', [2]: 'max'})
The dictionary keys are column names. We count 'id' and find max of 'price'.
Fill all three blanks to create a dictionary for aggregation: sum 'quantity', avg 'sales', and min 'discount'.
agg_df = df.groupBy('region').agg([1]: 'sum', [2]: [3], 'discount': 'min'})
The dictionary keys are column names and values are aggregation functions. We sum 'quantity', average 'sales', and find min 'discount'.