Skip to content

Updated documentation pandas alignment when setting #54240

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

Merged
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
13 changes: 12 additions & 1 deletion doc/source/user_guide/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ columns.

.. warning::

pandas aligns all AXES when setting ``Series`` and ``DataFrame`` from ``.loc``, and ``.iloc``.
pandas aligns all AXES when setting ``Series`` and ``DataFrame`` from ``.loc``.

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

Expand All @@ -172,6 +172,17 @@ columns.
df.loc[:, ['B', 'A']] = df[['A', 'B']].to_numpy()
df[['A', 'B']]

However, pandas does not align AXES when setting ``Series`` and ``DataFrame`` from ``.iloc``
because ``.iloc`` operates by position.

This will modify ``df`` because the column alignment is not done before value assignment.

.. ipython:: python

df[['A', 'B']]
df.iloc[:, [1, 0]] = df[['A', 'B']]
df[['A','B']]


Attribute access
----------------
Expand Down