I need to perform column operations in a Pandas dataframe based on conditions. something like:
divide 'colB' by 1000 IF 'colA' is 'KG' ELSE 'colB'
I have already tried a normal FOR loop to check each element but it takes time. I need a solution similar to what is discussed here but with an ELSE statement as well. Pandas mathmatical operation, conditional on column value
I need something like:
df['TON'] = df.loc[df.colA.eq('KG'), 'colB'].divide(1000)
ELSE...
It should fill with original value in colB if colA is not 'KG'.