This solution eludes me

In the Data Aggregator series, lesson 9 of 14, the instructions ask you to pass a function into the groupby.agg() method, then assign the result to mean_max_dif.

The solution broke my brain a little bit because the answer is groupby.agg([function]) and no arguments.

here is the line: mean_max_dif = happy_grouped.agg(dif)

The function is called dif. How is it possible that this code works without passing an argument into the function? How does the code no what to act on without looking like this instead:

mean_max_dif = happy_grouped.agg(dif([Insert Group Here]))

The function header is def dif(group), so isn’t an argument required?

hi @superheroslogan

The trickster here is .agg method.

When we apply the agg method to the Series happy_grouped and call the function dif, agg method makes each and every element of the series to be passed as an argument to the dif function.

These posts might be helpful too:

  1. Python | Pandas Series.agg() - GeeksforGeeks

  2. Mission 345 Slide 2 - doesn't understand the instruction "pass it into the function without the parentheses" - #4 by MatthewCH

  3. and if the function requires named position arguments then we need to pass the arguments, as given in official doc - pandas.Series.agg — pandas 1.3.2 documentation