use Series.between
hold_x = ~(df['X'].between(3, 10) | df['X'].between(33, 40))
hold_y = ~df['Y'].between(3, 37)
df['X'] = df['X'].where(hold_x | hold_y)
You could also use isin
+ range()
.
the difference is that in this way you can include only the left limit:
df['X'].isin(range(3, 10))
CLICK HERE to find out more related problems solutions.