Skip to content

Commit b6b7b02

Browse files
committed
precommit
1 parent f322d9e commit b6b7b02

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

doc/source/user_guide/user_defined_functions.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,25 @@ while preserving the original shape of the object.
151151

152152
.. ipython:: python
153153
154-
# Sample DataFrame
155-
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
154+
# Sample DataFrame
155+
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
156156
157-
# User-Defined Function
158-
def double(x):
159-
return x * 2
157+
# User-Defined Function
158+
def double(x):
159+
return x * 2
160160
161-
# Apply transform
162-
df_transformed = df.transform(double)
163-
print(df_transformed)
161+
# Apply transform
162+
df_transformed = df.transform(double)
163+
print(df_transformed)
164164
165-
# This works with lambda functions too
166-
df_lambda = df.transform(lambda x: x * 2)
167-
print(df_lambda)
165+
# This works with lambda functions too
166+
df_lambda = df.transform(lambda x: x * 2)
167+
print(df_lambda)
168168
169-
Attempting to use common aggregation functions such as `mean` or `sum` will result in
169+
Attempting to use common aggregation functions such as ``mean`` or ``sum`` will result in
170170
values being broadcasted to the original dimensions:
171171

172-
.. ipython:: python
172+
.. ipython:: python
173173
174174
# Sample DataFrame
175175
df = pd.DataFrame({
@@ -197,7 +197,7 @@ match particular conditions.
197197
:meth:`DataFrame.filter` does not accept user-defined functions, but can accept
198198
list comprehensions that have user-defined functions applied to them.
199199

200-
.. ipython:: python
200+
.. ipython:: python
201201
202202
# Sample DataFrame
203203
df = pd.DataFrame({
@@ -267,7 +267,7 @@ Performance Considerations
267267

268268
While user-defined functions provide flexibility, their use is currently discouraged as they can introduce
269269
performance issues, especially when written in pure Python. To improve efficiency,
270-
consider using built-in `NumPy` or `pandas` functions instead of user-defined functions
270+
consider using built-in ``NumPy`` or ``pandas`` functions instead of user-defined functions
271271
for common operations.
272272

273273
.. note::
@@ -302,4 +302,4 @@ with user-defined functions because they leverage highly optimized C functions
302302
via NumPy to process entire arrays at once. This approach avoids the overhead of looping
303303
through rows in Python and making separate function calls for each row, which is slow and
304304
inefficient. Additionally, NumPy arrays benefit from memory efficiency and CPU-level
305-
optimizations, making vectorized operations the preferred choice whenever possible.
305+
optimizations, making vectorized operations the preferred choice whenever possible.

0 commit comments

Comments
 (0)