pandas.DataFrame.agg | 您所在的位置:网站首页 › agg品牌怎么样 › pandas.DataFrame.agg |
Aggregate using one or more operations over the specified axis. Parameters: funcfunction, str, list or dictFunction to use for aggregating the data. If a function, must either work when passed a DataFrame or when passed to DataFrame.apply. Accepted combinations are: function string function name list of functions and/or function names, e.g. [np.sum, 'mean'] dict of axis labels -> functions, function names or list of such. axis{0 or ‘index’, 1 or ‘columns’}, default 0If 0 or ‘index’: apply function to each column. If 1 or ‘columns’: apply function to each row. *argsPositional arguments to pass to func. **kwargsKeyword arguments to pass to func. Returns: scalar, Series or DataFrameThe return can be: scalar : when Series.agg is called with single function Series : when DataFrame.agg is called with a single function DataFrame : when DataFrame.agg is called with several functions See also DataFrame.applyPerform any type of operations. DataFrame.transformPerform transformation type operations. pandas.DataFrame.groupbyPerform operations over groups. pandas.DataFrame.resamplePerform operations over resampled bins. pandas.DataFrame.rollingPerform operations over rolling window. pandas.DataFrame.expandingPerform operations over expanding window. pandas.core.window.ewm.ExponentialMovingWindowPerform operation over exponential weighted window. Notes The aggregation operations are always performed over an axis, either the index (default) or the column axis. This behavior is different from numpy aggregation functions (mean, median, prod, sum, std, var), where the default is to compute the aggregation of the flattened array, e.g., numpy.mean(arr_2d) as opposed to numpy.mean(arr_2d, axis=0). agg is an alias for aggregate. Use the alias. Functions that mutate the passed object can produce unexpected behavior or errors and are not supported. See Mutating with User Defined Function (UDF) methods for more details. A passed user-defined-function will be passed a Series for evaluation. Examples >>> df = pd.DataFrame([[1, 2, 3], ... [4, 5, 6], ... [7, 8, 9], ... [np.nan, np.nan, np.nan]], ... columns=['A', 'B', 'C'])Aggregate these functions over the rows. >>> df.agg(['sum', 'min']) A B C sum 12.0 15.0 18.0 min 1.0 2.0 3.0Different aggregations per column. >>> df.agg({'A' : ['sum', 'min'], 'B' : ['min', 'max']}) A B sum 12.0 NaN min 1.0 2.0 max NaN 8.0Aggregate different functions over the columns and rename the index of the resulting DataFrame. >>> df.agg(x=('A', 'max'), y=('B', 'min'), z=('C', 'mean')) A B C x 7.0 NaN NaN y NaN 2.0 NaN z NaN NaN 6.0Aggregate over the columns. >>> df.agg("mean", axis="columns") 0 2.0 1 5.0 2 8.0 3 NaN dtype: float64 |
CopyRight 2018-2019 实验室设备网 版权所有 |