Skip to content

Commit 40ba6eb

Browse files
zhangxiangnickjreback
authored andcommitted
DOC: add warning section in indexing docs
Replace PR #13060 close #12947 Author: Xiang Zhang <[email protected]> Closes #13070 from zhangxiangnick/doc_indexing_v2 and squashes the following commits: f9ade87 [Xiang Zhang] add warning section in indexing doc.
1 parent b2009e6 commit 40ba6eb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

doc/source/indexing.rst

+20
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,26 @@ raised. Multiple columns can also be set in this manner:
191191
You may find this useful for applying a transform (in-place) to a subset of the
192192
columns.
193193

194+
.. warning::
195+
196+
pandas aligns all AXES when setting ``Series`` and ``DataFrame`` from ``.loc``, ``.iloc`` and ``.ix``.
197+
198+
This will **not** modify ``df`` because the column alignment is before value assignment.
199+
200+
.. ipython:: python
201+
202+
df[['A', 'B']]
203+
df.loc[:,['B', 'A']] = df[['A', 'B']]
204+
df[['A', 'B']]
205+
206+
The correct way is to use raw values
207+
208+
.. ipython:: python
209+
210+
df.loc[:,['B', 'A']] = df[['A', 'B']].values
211+
df[['A', 'B']]
212+
213+
194214
Attribute Access
195215
----------------
196216

0 commit comments

Comments
 (0)