Skip to content

Commit 0d02d64

Browse files
committed
updated documentation links
1 parent 90a2d24 commit 0d02d64

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

doc/source/user_guide/user_defined_functions.rst

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,24 @@ Methods that support User-Defined Functions
3838

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

41-
* :meth:`DataFrame.apply` - A flexible method that allows applying a function to Series,
41+
* :meth:`~DataFrame.apply` - A flexible method that allows applying a function to Series,
4242
DataFrames, or groups of data.
43-
* :meth:`DataFrame.agg` (Aggregate) - Used for summarizing data, supporting multiple
43+
* :meth:`~DataFrame.agg` (Aggregate) - Used for summarizing data, supporting multiple
4444
aggregation functions.
45-
* :meth:`DataFrame.transform` - Applies a function to groups while preserving the shape of
45+
* :meth:`~DataFrame.transform` - Applies a function to groups while preserving the shape of
4646
the original data.
47-
* :meth:`DataFrame.filter` - Filters groups based on a list of Boolean conditions.
48-
* :meth:`DataFrame.map` - Applies an element-wise function to a Series, useful for
47+
* :meth:`~DataFrame.filter` - Filters groups based on a list of Boolean conditions.
48+
* :meth:`~DataFrame.map` - Applies an element-wise function to a Series, useful for
4949
transforming individual values.
50-
* :meth:`DataFrame.pipe` - Allows chaining custom functions to process entire DataFrames or
50+
* :meth:`~DataFrame.pipe` - Allows chaining custom functions to process entire DataFrames or
5151
Series in a clean, readable manner.
5252

5353
All of these pandas methods can be used with both Series and DataFrame objects, providing versatile
5454
ways to apply UDFs across different pandas data structures.
5555

56+
.. note::
57+
Some of these methods are can also be applied to Groupby Objects. Refer to :ref:`groupby`.
58+
5659

5760
Choosing the Right Method
5861
-------------------------
@@ -70,7 +73,7 @@ Below is a table overview of all methods that accept UDFs:
7073
+------------------+--------------------------------------+---------------------------+--------------------+---------------------------+------------------------------------------+
7174
| :meth:`agg` | Aggregation | Yes | No | Fast (if using built-ins) | Custom aggregation logic |
7275
+------------------+--------------------------------------+---------------------------+--------------------+---------------------------+------------------------------------------+
73-
| :meth:`transform`| Transform without reducing dimensions| Yes | Yes | Fast (if vectorized) | Broadcast Element-wise transformations |
76+
| :meth:`transform`| Transform without reducing dimensions| Yes | Yes | Fast (if vectorized) | Broadcast element-wise transformations |
7477
+------------------+--------------------------------------+---------------------------+--------------------+---------------------------+------------------------------------------+
7578
| :meth:`map` | Element-wise mapping | Yes | Yes | Moderate | Simple element-wise transformations |
7679
+------------------+--------------------------------------+---------------------------+--------------------+---------------------------+------------------------------------------+
@@ -89,7 +92,7 @@ that cannot be achieved with built-in pandas functions.
8992
When to use: :meth:`DataFrame.apply` is suitable when no alternative vectorized method is available, but consider
9093
optimizing performance with vectorized operations wherever possible.
9194

92-
Examples of usage can be found at :meth:`DataFrame.apply`
95+
Examples of usage can be found :ref:`here<api.dataframe.apply>`.
9396

9497
:meth:`DataFrame.agg`
9598
~~~~~~~~~~~~~~~~~~~~~
@@ -100,7 +103,7 @@ specifically designed for aggregation operations.
100103
When to use: Use :meth:`DataFrame.agg` for performing aggregations like sum, mean, or custom aggregation
101104
functions across groups.
102105

103-
Examples of usage can be found at :meth:`DataFrame.agg <api.dataframe.agg>`
106+
Examples of usage can be found :ref:`here<api.dataframe.agg>`.
104107

105108
:meth:`DataFrame.transform`
106109
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -110,7 +113,7 @@ It’s generally faster than apply because it can take advantage of pandas' inte
110113

111114
When to use: When you need to perform element-wise transformations that retain the original structure of the DataFrame.
112115

113-
Documentation: DataFrame.transform
116+
Documentation can be found :ref:`here<api.dataframe.transform>`.
114117

115118
Attempting to use common aggregation functions such as ``mean`` or ``sum`` will result in
116119
values being broadcasted to the original dimensions:
@@ -162,6 +165,9 @@ When to use: Use :meth:`DataFrame.filter` when you want to use a UDF to create a
162165
df_filtered = df[[col for col in df.columns if is_long_name(col)]]
163166
print(df_filtered)
164167
168+
Since filter does not direclty accept a UDF, you have to apply the UDF indirectly,
169+
such as by using list comprehensions.
170+
165171
:meth:`DataFrame.map`
166172
~~~~~~~~~~~~~~~~~~~~~
167173

@@ -170,7 +176,7 @@ for this purpose compared to :meth:`DataFrame.apply` because of its better perfo
170176

171177
When to use: Use map for applying element-wise UDFs to DataFrames or Series.
172178

173-
Documentation: DataFrame.map
179+
Documentation can be found :ref:`here<api.dataframe.map>`.
174180

175181
:meth:`DataFrame.pipe`
176182
~~~~~~~~~~~~~~~~~~~~~~
@@ -180,7 +186,7 @@ It is a helpful tool for organizing complex data processing workflows.
180186

181187
When to use: Use pipe when you need to create a pipeline of transformations and want to keep the code readable and maintainable.
182188

183-
Documentation: DataFrame.pipe
189+
Documentation can be found :ref:`here<api.dataframe.pipe>`.
184190

185191

186192
Best Practices
@@ -198,9 +204,9 @@ for common operations.
198204
Vectorized Operations
199205
~~~~~~~~~~~~~~~~~~~~~
200206

201-
Below is an example of vectorized operations in pandas:
207+
Below is a comparison of using UDFs versus using Vectorized Operations:
202208

203-
.. code-block:: text
209+
.. code-block:: python
204210
205211
# User-defined function
206212
def calc_ratio(row):
@@ -215,8 +221,8 @@ Measuring how long each operation takes:
215221

216222
.. code-block:: text
217223
218-
Vectorized: 0.0043 secs
219224
User-defined function: 5.6435 secs
225+
Vectorized: 0.0043 secs
220226
221227
Vectorized operations in pandas are significantly faster than using :meth:`DataFrame.apply`
222228
with UDFs because they leverage highly optimized C functions

0 commit comments

Comments
 (0)