Skip to content

Commit ed94af9

Browse files
jamie-harnessraj-thapamroeschke
authored
Updated documentation pandas alignment when setting (pandas-dev#54240) (#12)
* pandas-dev#13950 - Updated documentation on pandas alignment when setting * Update doc/source/user_guide/indexing.rst --------- Co-authored-by: raj-thapa <[email protected]> Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 9d5e34a commit ed94af9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

doc/source/user_guide/indexing.rst

+12-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ columns.
155155

156156
.. warning::
157157

158-
pandas aligns all AXES when setting ``Series`` and ``DataFrame`` from ``.loc``, and ``.iloc``.
158+
pandas aligns all AXES when setting ``Series`` and ``DataFrame`` from ``.loc``.
159159

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

@@ -172,6 +172,17 @@ columns.
172172
df.loc[:, ['B', 'A']] = df[['A', 'B']].to_numpy()
173173
df[['A', 'B']]
174174
175+
However, pandas does not align AXES when setting ``Series`` and ``DataFrame`` from ``.iloc``
176+
because ``.iloc`` operates by position.
177+
178+
This will modify ``df`` because the column alignment is not done before value assignment.
179+
180+
.. ipython:: python
181+
182+
df[['A', 'B']]
183+
df.iloc[:, [1, 0]] = df[['A', 'B']]
184+
df[['A','B']]
185+
175186
176187
Attribute access
177188
----------------

0 commit comments

Comments
 (0)