-
Notifications
You must be signed in to change notification settings - Fork 0
/
window_calc.py
22 lines (18 loc) · 809 Bytes
/
window_calc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Illustration of pipes using window calculations"""
def window_calc(df, func, agg_dict, *args, **kwargs):
"""
Run a window calculation of your choice on a `DataFrame` object.
Parameters:
- df: The `DataFrame` object to run the calculation on.
- func: The window calculation method that takes `df`
as the first argument.
- agg_dict: Information to pass to `agg()`, could be a
dictionary mapping the columns to the aggregation
function to use, a string name for the function,
or the function itself.
- args: Positional arguments to pass to `func`.
- kwargs: Keyword arguments to pass to `func`.
Returns:
A new `DataFrame` object.
"""
return df.pipe(func, *args, **kwargs).agg(agg_dict)