You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/user_guide/dsintro.rst
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -650,12 +650,12 @@ row-wise. For example:
650
650
651
651
df - df.iloc[0]
652
652
653
-
When using a Python list in arithmetic operations with a DataFrame, the behavior is not element-wise broadcasting.
654
-
Instead, the list is treated as a single object and the operation is performed column-wise, resulting in unexpected output (e.g. arrays inside each cell).
653
+
Use .add(array, axis=0) to apply row-wise broadcasting when the array length matches the number of rows —
654
+
this ensures element-wise operations are performed across each row, rather than mistakenly aligning with columns.
655
655
656
656
.. ipython:: python
657
657
658
-
df+np.array([1, 2, 3])
658
+
df.add(np.array([1, 2, 3]), axis=0)
659
659
660
660
For explicit control over the matching and broadcasting behavior, see the
661
661
section on :ref:`flexible binary operations <basics.binop>`.
0 commit comments