If you should get equal (or almost equal) bins, then here is a trick you can use with qcut. Using the same data as the accepted answer, we can force them into equal bunkers by adding some random noise to the original test list and binning according to these values.
test_list = [ 11, 18, 27, 30, 30, 31, 36, 40, 45, 53 ] np.random.seed(42) #set this for reproducible results test_list_rnd = np.array(test_list) + np.random.random(len(test_list)) #add noise to data test_series = pd.Series(test_list_rnd, name='value_rank') pd.qcut(test_series, 5, retbins=True, labels=False)
Output:
(0 0 1 0 2 1 3 2 4 1 5 2 6 3 7 3 8 4 9 4 Name: value_rank, dtype: int64, array([ 11.37454012, 25.97573801, 30.42160255, 33.11683016, 41.81316392, 53.70807258]))
So now we have two 0, two 1, two 2 and two 4!
Renouncement
Obviously, use this at your discretion, because the results may vary depending on your data; for example, how large is your dataset and / or interval, for example. The above βtrickβ works well for integers, because although we βstuffβ test_list, it will still order in the sense that there will not be a value in group 0 that exceeds the value in group 1 (possibly equal, but not more). If, however, you have floats, this can be difficult, and you may need to reduce the size of your noise accordingly. For example, if you had floating values, such as 2.1, 5.3, 5.3, 5.4, etc., you should reduce the noise by dividing it by 10: np.random.random (len (test_list)) / 10. If you swim arbitrarily for a long time, but you probably will not have this problem, first of all, given the noise already present in the "real" data.