File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -209,11 +209,12 @@ either match on the *index* or *columns* via the **axis** keyword:
209
209
df.sub(column, axis = " index" )
210
210
df.sub(column, axis = 0 )
211
211
212
- Be careful when using raw Python lists in binary operations with DataFrames.
213
- Unlike NumPy arrays or Series, lists are not broadcast across rows or columns.
214
- Instead, pandas attempts to match the entire list against a single axis, which may lead to confusing results such as Series of arrays.
215
- To ensure proper broadcasting behavior, use a NumPy array or Series with explicit index or shape.
216
- Furthermore you can align a level of a MultiIndexed DataFrame with a Series.
212
+ Use .add(array, axis=0) to broadcast values row-wise, ensuring each element in the array is
213
+ applied to the corresponding row. This avoids accidental column alignment and preserves expected element-wise behavior.
214
+
215
+ .. ipython :: python
216
+
217
+ df.add(np.array([1 , 2 , 3 ]), axis = 0 )
217
218
218
219
.. ipython :: python
219
220
You can’t perform that action at this time.
0 commit comments