Complete the code to group the DataFrame by the 'category' column.
grouped = df.groupby([1])To group by a column name, you must pass the column name as a string to groupby. So, 'category' is correct.
Complete the code to calculate the mean of each group.
result = df.groupby('category').[1]()
sum() instead of mean().count() which counts entries, not averages.The mean() function calculates the average value for each group.
Fix the error in this code to avoid slow performance when grouping large DataFrames.
result = df.groupby('category')[[1]].mean()
df['value'] instead of the column name string.df.columns which is a list of all columns.Passing the column name as a string inside the groupby selection is efficient. Using df['value'] or df.columns causes unnecessary overhead.
Fill both blanks to create a dictionary of group sizes for groups with more than 5 entries.
sizes = {group: len(data) for group, data in df.groupby([1]) if len(data) [2] 5}We group by the 'category' column and keep groups with length greater than 5.
Fill all three blanks to create a dictionary with group names in uppercase and sum of 'value' for groups with sum greater than 10.
result = {group[1]: data['[2]'].sum() for group, data in df.groupby('[3]') if data['value'].sum() > 10}The group name is converted to uppercase with .upper(). We sum the 'value' column for groups grouped by 'category'.