Feature Engineering for Machine Learning in Python
Robert O'Callaghan
Director of Data Science, Ordergroove
df['Binary_Violation'] = 0
df.loc[df['Number_of_Violations'] > 0, 'Binary_Violation'] = 1
import numpy as np
df['Binned_Group'] = pd.cut(
df['Number_of_Violations'],
bins=[-np.inf, 0, 2, np.inf],
labels=[1, 2, 3]
)
Feature Engineering for Machine Learning in Python