Skip to content

DOC: add warning section in indexing docs #13070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions doc/source/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,31 @@ raised. Multiple columns can also be set in this manner:
You may find this useful for applying a transform (in-place) to a subset of the
columns.

.. warning::

pandas aligns index when setting ``Series`` and ``DataFrame`` from ``.loc``, ``.iloc`` and ``.ix``.

This will **not** modify ``df`` because index alignment is before value assignment.

.. ipython:: python

df[['A', 'B']]
df.loc[:,['B', 'A']] = df[['A', 'B']]
df[['A', 'B']]

The correct way is to use raw values

.. ipython:: python

df.loc[:,['B', 'A']] = df[['A', 'B']].values
df[['A', 'B']]

This will also work because pandas ignores index alignment in column assignment

.. code-block:: python

df[['B', 'A']] = df[['A', 'B']]

Attribute Access
----------------

Expand Down