|
107 | 107 | _shared_doc_kwargs = dict( |
108 | 108 | axes='index, columns', klass='DataFrame', |
109 | 109 | axes_single_arg="{0 or 'index', 1 or 'columns'}", |
| 110 | + axis=""" |
| 111 | + axis : {0 or 'index', 1 or 'columns'}, default 0 |
| 112 | + - 0 or 'index': apply function to each column. |
| 113 | + - 1 or 'columns': apply function to each row.""", |
110 | 114 | optional_by=""" |
111 | 115 | by : str or list of str |
112 | 116 | Name or list of names to sort by. |
@@ -4460,9 +4464,9 @@ def pivot(self, index=None, columns=None, values=None): |
4460 | 4464 |
|
4461 | 4465 | Reshape data (produce a "pivot" table) based on column values. Uses |
4462 | 4466 | unique values from specified `index` / `columns` to form axes of the |
4463 | | - resulting DataFrame. This function does not support data aggregation, |
4464 | | - multiple values will result in a MultiIndex in the columns. See the |
4465 | | - :ref:`User Guide <reshaping>` for more on reshaping. |
| 4467 | + resulting DataFrame. This function does not support data |
| 4468 | + aggregation, multiple values will result in a MultiIndex in the |
| 4469 | + columns. See the :ref:`User Guide <reshaping>` for more on reshaping. |
4466 | 4470 |
|
4467 | 4471 | Parameters |
4468 | 4472 | ---------- |
@@ -4980,36 +4984,59 @@ def _gotitem(self, key, ndim, subset=None): |
4980 | 4984 | return self[key] |
4981 | 4985 |
|
4982 | 4986 | _agg_doc = dedent(""" |
| 4987 | + Notes |
| 4988 | + ----- |
| 4989 | + The aggregation operations are always performed over an axis, either the |
| 4990 | + index (default) or the column axis. This behavior is different from |
| 4991 | + `numpy` aggregation functions (`mean`, `median`, `prod`, `sum`, `std`, |
| 4992 | + `var`), where the default is to compute the aggregation of the flattened |
| 4993 | + array, e.g., ``numpy.mean(arr_2d)`` as opposed to ``numpy.mean(arr_2d, |
| 4994 | + axis=0)``. |
| 4995 | +
|
| 4996 | + `agg` is an alias for `aggregate`. Use the alias. |
| 4997 | +
|
4983 | 4998 | Examples |
4984 | 4999 | -------- |
| 5000 | + >>> df = pd.DataFrame([[1, 2, 3], |
| 5001 | + ... [4, 5, 6], |
| 5002 | + ... [7, 8, 9], |
| 5003 | + ... [np.nan, np.nan, np.nan]], |
| 5004 | + ... columns=['A', 'B', 'C']) |
4985 | 5005 |
|
4986 | | - >>> df = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C'], |
4987 | | - ... index=pd.date_range('1/1/2000', periods=10)) |
4988 | | - >>> df.iloc[3:7] = np.nan |
4989 | | -
|
4990 | | - Aggregate these functions across all columns |
| 5006 | + Aggregate these functions over the rows. |
4991 | 5007 |
|
4992 | 5008 | >>> df.agg(['sum', 'min']) |
4993 | | - A B C |
4994 | | - sum -0.182253 -0.614014 -2.909534 |
4995 | | - min -1.916563 -1.460076 -1.568297 |
| 5009 | + A B C |
| 5010 | + sum 12.0 15.0 18.0 |
| 5011 | + min 1.0 2.0 3.0 |
4996 | 5012 |
|
4997 | | - Different aggregations per column |
| 5013 | + Different aggregations per column. |
4998 | 5014 |
|
4999 | 5015 | >>> df.agg({'A' : ['sum', 'min'], 'B' : ['min', 'max']}) |
5000 | | - A B |
5001 | | - max NaN 1.514318 |
5002 | | - min -1.916563 -1.460076 |
5003 | | - sum -0.182253 NaN |
| 5016 | + A B |
| 5017 | + max NaN 8.0 |
| 5018 | + min 1.0 2.0 |
| 5019 | + sum 12.0 NaN |
| 5020 | +
|
| 5021 | + Aggregate over the columns. |
| 5022 | +
|
| 5023 | + >>> df.agg("mean", axis="columns") |
| 5024 | + 0 2.0 |
| 5025 | + 1 5.0 |
| 5026 | + 2 8.0 |
| 5027 | + 3 NaN |
| 5028 | + dtype: float64 |
5004 | 5029 |
|
5005 | 5030 | See also |
5006 | 5031 | -------- |
5007 | | - pandas.DataFrame.apply |
5008 | | - pandas.DataFrame.transform |
5009 | | - pandas.DataFrame.groupby.aggregate |
5010 | | - pandas.DataFrame.resample.aggregate |
5011 | | - pandas.DataFrame.rolling.aggregate |
5012 | | -
|
| 5032 | + DataFrame.apply : Perform any type of operations. |
| 5033 | + DataFrame.transform : Perform transformation type operations. |
| 5034 | + pandas.core.groupby.GroupBy : Perform operations over groups. |
| 5035 | + pandas.core.resample.Resampler : Perform operations over resampled bins. |
| 5036 | + pandas.core.window.Rolling : Perform operations over rolling window. |
| 5037 | + pandas.core.window.Expanding : Perform operations over expanding window. |
| 5038 | + pandas.core.window.EWM : Perform operation over exponential weighted |
| 5039 | + window. |
5013 | 5040 | """) |
5014 | 5041 |
|
5015 | 5042 | @Appender(_agg_doc) |
|
0 commit comments