Hi I would like to know the best way to do operations on columns in python using pandas.
I have a classical database which I have loaded as a dataframe, and I often have
There's lots of ways of doing this, but here's the pattern I find easiest to read.
#Assume df is a Panda's dataframe object idx = df.loc[:, 'A'] > x df.loc[idx, 'A'] = df.loc[idx, 'C'] - df.loc[idx, 'D']
Setting the elements less than x is as easy as df.loc[~idx, 'A'] = 0