The main meaning of binning is to group values into "Bins", or convert numerical values into categorical. For example let's have different degrees of temperatures with different values [-15-50], by group these values into 4 category, {[-15-0], [0-8], [9-25], [26-50]} then we will have good representation and can name this category with (freeze, very_cold, cold, hot).
The Code:
bins = np.linspace(min(df["temp"]), max(df["temp"]), 4)group_names = ["freeze", "very_cold", "cold", "hot"]
df["temp-binned"] = pd.cut(df["temp"], bins, labels = group_name, include_lowest=True),
0 Comments:
Post a Comment