Binning Numeric Values
Medium
feature-engineering
Capital One
Stripe
Given a list of numeric values and bin edges, assign each value to a bin. Return the bin index for each value. Values below the first edge get bin 0, values between edge[i] and edge[i+1] get bin i+1, etc.
Example
binning([5, 15, 25, 35, 45], [10, 20, 30, 40])
# => [0, 1, 2, 3, 4]
Test Cases
Python Editor
Output
Click "Run" to see results...