Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DOC: User Guide Page on user-defined functions #61195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 18, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated definition section and performance section title
  • Loading branch information
arthurlw committed Apr 20, 2025
commit c00d1d243bd33449d27e42cd355f55d9ad7df900
29 changes: 13 additions & 16 deletions 29 doc/source/user_guide/user_defined_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,17 @@ Methods that support User-Defined Functions

User-Defined Functions can be applied across various pandas methods:

* :meth:`~DataFrame.apply` - A flexible method that allows applying a function to Series and
DataFrames.
* :meth:`~DataFrame.agg` (Aggregate) - Used for summarizing data, supporting custom
aggregation functions.
* :meth:`~DataFrame.transform` - Applies a function to Series and Dataframes while preserving the shape of
the original data.
* :meth:`~DataFrame.filter` - Filters Series and Dataframes based on a list of Boolean conditions.
* :meth:`~DataFrame.map` - Applies an element-wise function to a Series or Dataframe, useful for
transforming individual values.
* :meth:`~DataFrame.pipe` - Allows chaining custom functions to process Series or
Dataframes in a clean, readable manner.

All of these pandas methods can be used with both Series and DataFrame objects, providing versatile
ways to apply UDFs across different pandas data structures.
+-------------------+------------------------+--------------------------+---------------------------------------------------------------------------+
| Method | Function Input | Function Output | Description |
+===================+========================+==========================+===========================================================================+
| map | Scalar | Scalar | Maps each element to the element returned by the function element-wise |
| apply (axis=0) | Column (Series) | Column (Series) | Apply a function to each column |
| apply (axis=1) | Row (Series) | Row (Series) | Apply a function to each row |
| agg | Series/DataFrame | Scalar or Series | Aggregate and summarizes values, e.g., sum or custom reducer |
| transform | Series/DataFrame | Same shape as input | Transform values while preserving shape |
| filter | Series/DataFrame | Series/DataFrame | Filter data using a boolean array |
| pipe | Series/DataFrame | Series/DataFrame | Chain UDFs together to apply to Series or Dataframe |
+-------------------+------------------------+--------------------------+---------------------------------------------------------------------------+

.. note::
Some of these methods are can also be applied to groupby, resample, and various window objects.
Expand Down Expand Up @@ -243,8 +240,8 @@ When to use: Use pipe when you need to create a pipeline of operations and want
Documentation can be found at :meth:`~DataFrame.pipe`.


Best Practices
--------------
Performance
-----------

While UDFs provide flexibility, their use is currently discouraged as they can introduce
performance issues, especially when written in pure Python. To improve efficiency,
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.