I am using pandas version 0.14.1 with Python 2.7.5, and I have a data frame with three columns, e.g.:
import pandas as pd
d = {\'L\': [\'left\', \'right\',
You can also do this with np.select and df.where i.e
Option 1: np.select
df[['L','R']] = pd.np.select(df['VALUE'] == 1, df[['R','L']].values, df[['L','R']].values)
Option 2: df.where
df[['L','R']] = df[['R','L']].where(df['VALUE'] == 1, df[['L','R']].values)
Option 3: df.mask
df[['L','R']] = df[['L','R']].mask( df['VALUE'] == 1, df[['R','L']].values)
Output:
L R VALUE
0 left right -1
1 left right 1
2 left right -1
3 left right 1
4 left right -1
5 left right 1