# Instead of this df['category'] = df.apply( lambda row: 'high' if row['sales'] > 5000 else 'low', axis=1 ) # Do this df['category'] = np.where(df['sales'] > 5000, 'high', 'low')