|
11 | 11 | from pandas.core.panel import Panel
|
12 | 12 | from pandas.util.decorators import cache_readonly, Appender
|
13 | 13 | from pandas.util.compat import OrderedDict
|
| 14 | +from pandas.util.decorators import Appender |
14 | 15 | import pandas.core.algorithms as algos
|
15 | 16 | import pandas.core.common as com
|
16 | 17 | import pandas.lib as lib
|
17 | 18 |
|
| 19 | +_agg_doc = """Aggregate using input function or dict of {column -> function} |
| 20 | +
|
| 21 | +Parameters |
| 22 | +---------- |
| 23 | +arg : function or dict |
| 24 | + Function to use for aggregating groups. If a function, must either |
| 25 | + work when passed a DataFrame or when passed to DataFrame.apply. If |
| 26 | + pass a dict, the keys must be DataFrame column names |
| 27 | +
|
| 28 | +Notes |
| 29 | +----- |
| 30 | +Numpy functions mean/median/prod/sum/std/var are special cased so the |
| 31 | +default behavior is applying the function along axis=0 |
| 32 | +(e.g., np.mean(arr_2d, axis=0)) as opposed to |
| 33 | +mimicking the default Numpy behavior (e.g., np.mean(arr_2d)). |
| 34 | +
|
| 35 | +Returns |
| 36 | +------- |
| 37 | +aggregated : DataFrame |
| 38 | +""" |
18 | 39 |
|
19 | 40 | class GroupByError(Exception):
|
20 | 41 | pass
|
@@ -298,10 +319,8 @@ def apply(self, func, *args, **kwargs):
|
298 | 319 | def aggregate(self, func, *args, **kwargs):
|
299 | 320 | raise NotImplementedError
|
300 | 321 |
|
| 322 | + @Appender(_agg_doc) |
301 | 323 | def agg(self, func, *args, **kwargs):
|
302 |
| - """ |
303 |
| - See docstring for aggregate |
304 |
| - """ |
305 | 324 | return self.aggregate(func, *args, **kwargs)
|
306 | 325 |
|
307 | 326 | def _iterate_slices(self):
|
@@ -1508,21 +1527,8 @@ def _obj_with_exclusions(self):
|
1508 | 1527 | else:
|
1509 | 1528 | return self.obj
|
1510 | 1529 |
|
| 1530 | + @Appender(_agg_doc) |
1511 | 1531 | def aggregate(self, arg, *args, **kwargs):
|
1512 |
| - """ |
1513 |
| - Aggregate using input function or dict of {column -> function} |
1514 |
| -
|
1515 |
| - Parameters |
1516 |
| - ---------- |
1517 |
| - arg : function or dict |
1518 |
| - Function to use for aggregating groups. If a function, must either |
1519 |
| - work when passed a DataFrame or when passed to DataFrame.apply. If |
1520 |
| - pass a dict, the keys must be DataFrame column names |
1521 |
| -
|
1522 |
| - Returns |
1523 |
| - ------- |
1524 |
| - aggregated : DataFrame |
1525 |
| - """ |
1526 | 1532 | if isinstance(arg, basestring):
|
1527 | 1533 | return getattr(self, arg)(*args, **kwargs)
|
1528 | 1534 |
|
@@ -2238,10 +2244,10 @@ def _reorder_by_uniques(uniques, labels):
|
2238 | 2244 | np.mean: 'mean',
|
2239 | 2245 | np.prod: 'prod',
|
2240 | 2246 | np.std: 'std',
|
2241 |
| - np.var: 'var' |
| 2247 | + np.var: 'var', |
| 2248 | + np.median: 'median' |
2242 | 2249 | }
|
2243 | 2250 |
|
2244 |
| - |
2245 | 2251 | def _is_numeric_dtype(dt):
|
2246 | 2252 | typ = dt.type
|
2247 | 2253 | return (issubclass(typ, (np.number, np.bool_))
|
|
0 commit comments