Python: Assigning # values in a list to bins, by rounding up
问题 I want a function that can take a series and a set of bins, and basically round up to the nearest bin. For example: my_series = [ 1, 1.5, 2, 2.3, 2.6, 3] def my_function(my_series, bins): ... my_function(my_series, bins=[1,2,3]) > [1,2,2,3,3,3] This seems to be very close to what Numpy's Digitize is intended to do, but it produces the wrong values (asterisks for wrong values): np.digitize(my_series, bins= [1,2,3], right=False) > [1, 1*, 2, 2*, 2*, 3] The reason why it's wrong is clear from