Code Sample, a copy-pastable example if possible

# Your code here
df = pd.DataFrame({'a': range(4), 'b': range(4,8)})
df.loc[df.a==2, ['a', 'b']] = df.loc[df.a==2, ['b', 'a']]
print df

produces:

   a  b
0  0  4
1  1  5
2  2  6
3  3  7

Problem description

This should interchange the value for column and b for when a == 2. Right now it silently does nothing.

Expected Output

   a  b
0  0  4
1  1  5
2  6  2
3  3  7

Output of pd.show_versions()

# Paste the output here pd.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 2.7.11.final.0 python-bits: 64 OS: Darwin OS-release: 16.5.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: None.None pandas: 0.19.2 nose: 1.3.6 pip: 8.1.2 setuptools: 35.0.1 Cython: 0.24 numpy: 1.12.1 scipy: 0.18.1 statsmodels: 0.8.0rc1 xarray: None IPython: 5.2.2 sphinx: None patsy: 0.4.1 dateutil: 2.6.0 pytz: 2016.10 blosc: None bottleneck: None tables: None numexpr: None matplotlib: 1.5.3 openpyxl: None xlrd: 1.0.0 xlwt: None xlsxwriter: None lxml: None bs4: 4.4.0 html5lib: 0.9999999 httplib2: 0.9.2 apiclient: None sqlalchemy: 1.0.11 pymysql: None psycopg2: 2.6.1 (dt dec pq3 ext lo64) jinja2: 2.9.5 boto: 2.39.0 pandas_datareader: None

Comment From: jreback

this is shown as an example in the docs http://pandas.pydata.org/pandas-docs/stable/indexing.html#basics and is as expected

the axes align by definition

Comment From: rchurt

For anyone coming across this later, the correct way to do this is:

df = pd.DataFrame({'a': range(4), 'b': range(4,8)})
df.loc[df.a==2, ['a', 'b']] = df.loc[df.a==2, ['b', 'a']].to_numpy()
print df