File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,31 @@ raised. Multiple columns can also be set in this manner:
191
191
You may find this useful for applying a transform (in-place) to a subset of the
192
192
columns.
193
193
194
+ .. warning ::
195
+
196
+ pandas aligns index when setting ``Series `` and ``DataFrame `` from ``.loc ``, ``.iloc `` and ``.ix ``.
197
+
198
+ This will **not ** modify ``df `` because index 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
+ This will also work because pandas ignores index alignment in column assignment
214
+
215
+ .. code-block :: python
216
+
217
+ df[[' B' , ' A' ]] = df[[' A' , ' B' ]]
218
+
194
219
Attribute Access
195
220
----------------
196
221
You can’t perform that action at this time.
0 commit comments