how can i simplify conditions in pandas?

Use 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'] =, choices, default=df.X)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top