In [19]:
#http://pandas.pydata.org/pandas-docs/stable/cookbook.html
import pandas as pd
In [20]:
df = pd.DataFrame({'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
Out[20]:
In [21]:
#if-then...
#An if-then on one column
df.ix[df.AAA >= 5,'BBB'] = -1; df
Out[21]:
In [22]:
#An if-then with assignment to 2 columns:
df.ix[df.AAA >= 5,['BBB','CCC']] = 555; df
Out[22]:
In [23]:
#Add another line with different logic, to do the -else
df.ix[df.AAA < 5,['BBB','CCC']] = 2000; df
Out[23]:
In [23]: