I have a dataframe with 2 columns X and Y. I want to set up a new series which equals X when X=Y, and x/(Y-X) when X!=Y.
If try to do this:
df['temp'] = 0
df.loc[df.X == df.Y, 'temp'] = df.X
df.loc[df.X != df.Y, 'temp'] = df.X /(df.Y-df.X)
Z= df.temp
df = df.drop('temp', axis=1)
I get
ZeroDivisionError: float division by zero
Is there a better way to do this than running loops?