Unexpected Column Name

Screen Link: https://app.dataquest.io/m/343/data-aggregation/9/introduction-to-the-agg-method

My Code:

import numpy as np
grouped = happiness2015.groupby('Region')
happy_grouped = grouped['Happiness Score']

def dif(group):
    return (group.max() - group.mean())

mean_max_dif = happy_grouped.agg(dif)
print(mean_max_dif)

I expected the the column name to be be dif, but it is named “Happines Score” why is that?

image

dif is just a custom function you are applying to calculate the difference between mean and max. You are not naming the column as dif. The column which is grouped (in this case: Happiness Score) will have the same name as it was before in the original data.

2 Likes

Thanks :slight_smile:

1 Like