Complete the code to calculate the mean of each group using transform.
df['group_mean'] = df.groupby('group')['value'].[1](lambda x: x.mean())
The transform() function applies a function to each group and returns a result with the same shape as the original data, allowing group-level calculations to be assigned back to the DataFrame.
Complete the code to subtract the group mean from each value using transform.
df['value_centered'] = df['value'] - df.groupby('group')['value'].[1](lambda x: x.mean())
transform() returns a series aligned with the original data, so we can subtract the group mean from each value directly.
Fix the error in the code to correctly calculate the z-score within each group.
df['z_score'] = df.groupby('group')['value'].[1](lambda x: (x - x.mean()) / x.std())
transform() is needed here because it returns a series with the same shape as the original, allowing element-wise operations like z-score calculation within groups.
Fill both blanks to create a new column with the max value per group and then subtract the min value per group.
df['range'] = df.groupby('group')['value'].[1]('max') - df.groupby('group')['value'].[2]('min')
Using transform() for both max and min returns series aligned with the original data, allowing element-wise subtraction to get the range per group.
Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
lengths = {word: {BLANK_2}} for word in words if {{BLANK_2}}The dictionary comprehension syntax requires a colon between key and value. The value is the length of the word, and the condition filters words longer than 3 characters.