Use numpy.select
. It would be the fastest in performance.
import numpy as np
conditions = [(df.Y - df.Z) > df.X, (df.Y + df.Z) < df.X]
choices = [df.Y - df.Z, df.Y + df.Z]
df['A'] = np.select(conditions, choices, default=df.X)
CLICK HERE to find out more related problems solutions.