@@ -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
170170values 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
268268While user-defined functions provide flexibility, their use is currently discouraged as they can introduce
269269performance 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
271271for common operations.
272272
273273.. note ::
@@ -302,4 +302,4 @@ with user-defined functions because they leverage highly optimized C functions
302302via NumPy to process entire arrays at once. This approach avoids the overhead of looping
303303through rows in Python and making separate function calls for each row, which is slow and
304304inefficient. 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