@@ -843,10 +843,11 @@ Aggregation API
843843.. versionadded :: 0.20.0
844844
845845The aggregation API allows one to express possibly multiple aggregation operations in a single concise way.
846- This API is similar across pandas objects, :ref: `groupby aggregates <groupby.aggregate >`,
847- :ref: `window functions <stats.aggregate >`, and the :ref: `resample API <timeseries.aggregate >`.
846+ This API is similar across pandas objects, see :ref: `groupby API <groupby.aggregate >`, the
847+ :ref: `window functions API <stats.aggregate >`, and the :ref: `resample API <timeseries.aggregate >`.
848+ The entry point for aggregation is the method :meth: `~DataFrame.aggregate `, or the alias :meth: `~DataFrame.agg `.
848849
849- We will use a similar starting frame from above.
850+ We will use a similar starting frame from above:
850851
851852.. ipython :: python
852853
@@ -855,8 +856,8 @@ We will use a similar starting frame from above.
855856 tsdf.iloc[3 :7 ] = np.nan
856857 tsdf
857858
858- Using a single function is equivalent to `` .apply ` `; You can also pass named methods as strings.
859- This will return a Series of the output.
859+ Using a single function is equivalent to :meth: ` ~DataFrame .apply `; You can also pass named methods as strings.
860+ These will return a `` Series `` of the aggregated output:
860861
861862.. ipython :: python
862863
@@ -867,72 +868,68 @@ This will return a Series of the output.
867868 # these are equivalent to a ``.sum()`` because we are aggregating on a single function
868869 tsdf.sum()
869870
870- On a Series this will result in a scalar value
871+ Single aggregations on a `` Series `` this will result in a scalar value:
871872
872873.. ipython :: python
873874
874875 tsdf.A.agg(' sum' )
875876
876877
877- Aggregating multiple functions at once
878- ++++++++++++++++++++++++++++++++++++++
878+ Aggregating with multiple functions
879+ +++++++++++++++++++++++++++++++++++
879880
880- You can pass arguments as a list. The results of each of the passed functions will be a row in the resultant DataFrame.
881+ You can pass multiple aggregation arguments as a list.
882+ The results of each of the passed functions will be a row in the resultant ``DataFrame ``.
881883These are naturally named from the aggregation function.
882884
883885.. ipython :: python
884886
885887 tsdf.agg([' sum' ])
886888
887- Multiple functions yield multiple rows.
889+ Multiple functions yield multiple rows:
888890
889891.. ipython :: python
890892
891893 tsdf.agg([' sum' , ' mean' ])
892894
893- On a Series, multiple functions return a Series, indexed by the function names.
895+ On a `` Series `` , multiple functions return a `` Series `` , indexed by the function names:
894896
895897.. ipython :: python
896898
897899 tsdf.A.agg([' sum' , ' mean' ])
898900
899-
900- Aggregating with a dict of functions
901- ++++++++++++++++++++++++++++++++++++
902-
903- Passing a dictionary of column name to function or list of functions, to ``DataFame.agg ``
904- allows you to customize which functions are applied to which columns.
901+ Passing a ``lambda `` function will yield a ``<lambda> `` named row:
905902
906903.. ipython :: python
907904
908- tsdf.agg({ ' A ' : ' mean ' , ' B ' : ' sum ' } )
905+ tsdf.A. agg([ ' sum ' , lambda x : x.mean()] )
909906
910- Passing a list-like will generate a DataFrame output. You will get a matrix-like output
911- of all of the aggregators; some may be missing values.
907+ Passing a named function will yield that name for the row:
912908
913909.. ipython :: python
914910
915- tsdf.agg({' A' : [' mean' , ' min' ], ' B' : ' sum' })
916-
917- For a Series, you can pass a dict. You will get back a MultiIndex Series; The outer level will
918- be the keys, the inner the name of the functions.
911+ def mymean (x ):
912+ return x.mean()
919913
920- .. ipython :: python
914+ tsdf.A.agg([ ' sum ' , mymean])
921915
922- tsdf.A.agg({' foo' : [' sum' , ' mean' ]})
916+ Aggregating with a dict
917+ +++++++++++++++++++++++
923918
924- Alternatively, using multiple dictionaries, you can have renamed elements with the aggregation
919+ Passing a dictionary of column names to a scalar or a list of scalars, to ``DataFame.agg ``
920+ allows you to customize which functions are applied to which columns.
925921
926922.. ipython :: python
927923
928- tsdf.A. agg({' foo ' : ' sum ' , ' bar ' : ' mean ' })
924+ tsdf.agg({' A ' : ' mean ' , ' B ' : ' sum ' })
929925
930- Multiple keys will yield a MultiIndex Series. The outer level will be the keys, the inner
931- the names of the functions.
926+ Passing a list-like will generate a ``DataFrame `` output. You will get a matrix-like output
927+ of all of the aggregators. The output will consist of all unique functions. Those that are
928+ not noted for a particular column will be ``NaN ``:
932929
933930.. ipython :: python
934931
935- tsdf.A. agg({' foo ' : [' sum ' , ' mean' ] , ' bar ' : [ ' min' , ' max ' , lambda x : x. sum() + 1 ] })
932+ tsdf.agg({' A ' : [' mean' , ' min' ] , ' B ' : ' sum' })
936933
937934 .. _basics.aggregation.mixed_dtypes :
938935
@@ -980,7 +977,7 @@ Transform API
980977
981978.. versionadded :: 0.20.0
982979
983- The `` transform ` ` method returns an object that is indexed the same (same size)
980+ The :method: ` ~DataFrame. transform ` method returns an object that is indexed the same (same size)
984981as the original. This API allows you to provide *multiple * operations at the same
985982time rather than one-by-one. Its api is quite similar to the ``.agg `` API.
986983
@@ -1034,8 +1031,8 @@ resulting column names will be the transforming functions.
10341031 tsdf.A.transform([np.abs, lambda x : x+ 1 ])
10351032
10361033
1037- Transforming with a dict of functions
1038- +++++++++++++++++++++++++++++++++++++
1034+ Transforming with a dict
1035+ ++++++++++++++++++++++++
10391036
10401037
10411038Passing a dict of functions will will allow selective transforming per column.
@@ -1051,14 +1048,6 @@ selective transforms.
10511048
10521049 tsdf.transform({' A' : np.abs, ' B' : [lambda x : x+ 1 , ' sqrt' ]})
10531050
1054- On a Series, passing a dict allows renaming as in ``.agg() ``
1055-
1056- .. ipython :: python
1057-
1058- tsdf.A.transform({' foo' : np.abs})
1059- tsdf.A.transform({' foo' : np.abs, ' bar' : [lambda x : x+ 1 , ' sqrt' ]})
1060-
1061-
10621051 .. _basics.elementwise :
10631052
10641053Applying Elementwise Functions
0 commit comments