diff --git a/doc/source/user_guide/basics.rst b/doc/source/user_guide/basics.rst index 3fdd15462b51e..44aaf20693624 100644 --- a/doc/source/user_guide/basics.rst +++ b/doc/source/user_guide/basics.rst @@ -209,7 +209,9 @@ either match on the *index* or *columns* via the **axis** keyword: df.sub(column, axis="index") df.sub(column, axis=0) -Furthermore you can align a level of a MultiIndexed DataFrame with a Series. +.. ipython:: python + + df.add(np.array([1, 2, 3]), axis=0) .. ipython:: python diff --git a/doc/source/user_guide/dsintro.rst b/doc/source/user_guide/dsintro.rst index 89981786d60b5..385238c12f423 100644 --- a/doc/source/user_guide/dsintro.rst +++ b/doc/source/user_guide/dsintro.rst @@ -650,6 +650,13 @@ row-wise. For example: df - df.iloc[0] +Use .add(array, axis=0) to apply row-wise broadcasting when the array length matches the number of rows — +this ensures element-wise operations are performed across each row, rather than mistakenly aligning with columns. + +.. ipython:: python + + df.add(np.array([1, 2, 3]), axis=0) + For explicit control over the matching and broadcasting behavior, see the section on :ref:`flexible binary operations `.