December 2018
Beginner to intermediate
682 pages
18h 1m
English
Unfortunately, pandas does not have a direct way to use these additional arguments when using multiple aggregation functions together. For example, if you wish to aggregate using the pct_between and mean functions, you will get the following exception:
>>> college.groupby(['STABBR', 'RELAFFIL'])['UGDS'] \ .agg(['mean', pct_between], low=100, high=1000) TypeError: pct_between() missing 2 required positional arguments: 'low' and 'high'
Pandas is incapable of understanding that the extra arguments need to be passed to pct_between. In order to use our custom function with other built-in functions and even other custom functions, we can define a special type of nested function called a closure. We can use a generic closure to build ...