To bin a column with Python Pandas, we can use the cut
method.
For instance, we werite
bins = [0, 1, 5, 10, 25, 50, 100]
df['binned'] = pd.cut(df['percentage'], bins)
to add the binned
column by calling cut
with the data frame df
‘s percentage
column with the bins
.