@@ -151,25 +151,25 @@ while preserving the original shape of the object.
151
151
152
152
.. ipython :: python
153
153
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 ]})
156
156
157
- # User-Defined Function
158
- def double (x ):
159
- return x * 2
157
+ # User-Defined Function
158
+ def double (x ):
159
+ return x * 2
160
160
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)
164
164
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)
168
168
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
170
170
values being broadcasted to the original dimensions:
171
171
172
- .. ipython :: python
172
+ .. ipython :: python
173
173
174
174
# Sample DataFrame
175
175
df = pd.DataFrame({
@@ -197,7 +197,7 @@ match particular conditions.
197
197
:meth: `DataFrame.filter ` does not accept user-defined functions, but can accept
198
198
list comprehensions that have user-defined functions applied to them.
199
199
200
- .. ipython :: python
200
+ .. ipython :: python
201
201
202
202
# Sample DataFrame
203
203
df = pd.DataFrame({
@@ -267,7 +267,7 @@ Performance Considerations
267
267
268
268
While user-defined functions provide flexibility, their use is currently discouraged as they can introduce
269
269
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
271
271
for common operations.
272
272
273
273
.. note ::
@@ -302,4 +302,4 @@ with user-defined functions because they leverage highly optimized C functions
302
302
via NumPy to process entire arrays at once. This approach avoids the overhead of looping
303
303
through rows in Python and making separate function calls for each row, which is slow and
304
304
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