As shown in earlier answer: You can get the bin boundaries from qcut
using the retbins
parameter, as in the following:
q, bins = pd.qcut(a, 2, retbins=True)
Then you can use cut
to put values from another list into those "bins." For example:
myList = np.random.random(100)
# Define bin bounds that cover the range returned by random()
bins = [0, .1, .9, 1]
# Now we can get the "bin number" of each value in myList:
binNum = pd.cut(myList, bins, labels=False, include_lowest=True)
# And then we can count the number of values in each bin number:
np.bincount(binNum)
Be sure that your bin bounds cover the entire range of values that appear in your second list. To ensure this you might pad your bin boundaries with the max and min value. E.g.,
cutBins = [float('-inf')] + bins.tolist() + [float('inf')]