@@ -87,20 +87,17 @@ Methods that support User-Defined Functions
87
87
88
88
User-Defined Functions can be applied across various pandas methods:
89
89
90
- * :meth: `~DataFrame.apply ` - A flexible method that allows applying a function to Series and
91
- DataFrames.
92
- * :meth: `~DataFrame.agg ` (Aggregate) - Used for summarizing data, supporting custom
93
- aggregation functions.
94
- * :meth: `~DataFrame.transform ` - Applies a function to Series and Dataframes while preserving the shape of
95
- the original data.
96
- * :meth: `~DataFrame.filter ` - Filters Series and Dataframes based on a list of Boolean conditions.
97
- * :meth: `~DataFrame.map ` - Applies an element-wise function to a Series or Dataframe, useful for
98
- transforming individual values.
99
- * :meth: `~DataFrame.pipe ` - Allows chaining custom functions to process Series or
100
- Dataframes in a clean, readable manner.
101
-
102
- All of these pandas methods can be used with both Series and DataFrame objects, providing versatile
103
- ways to apply UDFs across different pandas data structures.
90
+ +-------------------+------------------------+--------------------------+---------------------------------------------------------------------------+
91
+ | Method | Function Input | Function Output | Description |
92
+ +===================+========================+==========================+===========================================================================+
93
+ | map | Scalar | Scalar | Maps each element to the element returned by the function element-wise |
94
+ | apply (axis=0) | Column (Series) | Column (Series) | Apply a function to each column |
95
+ | apply (axis=1) | Row (Series) | Row (Series) | Apply a function to each row |
96
+ | agg | Series/DataFrame | Scalar or Series | Aggregate and summarizes values, e.g., sum or custom reducer |
97
+ | transform | Series/DataFrame | Same shape as input | Transform values while preserving shape |
98
+ | filter | Series/DataFrame | Series/DataFrame | Filter data using a boolean array |
99
+ | pipe | Series/DataFrame | Series/DataFrame | Chain UDFs together to apply to Series or Dataframe |
100
+ +-------------------+------------------------+--------------------------+---------------------------------------------------------------------------+
104
101
105
102
.. note ::
106
103
Some of these methods are can also be applied to groupby, resample, and various window objects.
@@ -243,8 +240,8 @@ When to use: Use pipe when you need to create a pipeline of operations and want
243
240
Documentation can be found at :meth: `~DataFrame.pipe `.
244
241
245
242
246
- Best Practices
247
- --------------
243
+ Performance
244
+ -----------
248
245
249
246
While UDFs provide flexibility, their use is currently discouraged as they can introduce
250
247
performance issues, especially when written in pure Python. To improve efficiency,
0 commit comments