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
simplest according to me.
from random import randint, randrange, uniform
import pandas as pd
import numpy as np
df = pd.DataFrame({'a':randrange(0,10),'b':randrange(10,20),'c':np.random.randn(10)})
#If colC > 0,5, then ColC = ColB - Cola
df['c'][df['c'] > 0.5] = df['b'] - df['a']
Tested, it works.
a b c
2 11 -0.576309
2 11 -0.578449
2 11 -1.085822
2 11 9.000000
2 11 9.000000
2 11 -1.081405