Pandas has a method called cut that will do what you want:
import pandas as pd data = [{"low": 0, "high": 10, "name": "a"}, {"low": 10, "high": 20, "name": "b"}, {"low": 20, "high": 30, "name": "c"}, {"low": 30, "high": 40, "name": "d"}, {"low": 40, "high": 50, "name": "e"},] myDF = pd.DataFrame(data) #data to be binned mySeries = pd.Series([5.7, 30.4, 21, 35.1]) #create bins from original data bins = list(myDF["high"]) bins.insert(0,0) print pd.cut(mySeries, bins, labels = myDF["name"])
This will give you the following, which you can then return to some data frame or, nevertheless, want to save your data:
0 a 1 d 2 c 3 d dtype: category Categories (5, object): [a < b < c < d < e]
Depending on how irregular your bins are (and what you mean exactly by regular / irregular), you may have to resort to a loop cycle. I can't come up with the top of my head for an embedded device that will handle this for you, especially considering that it depends on the degree / type of irregularity in the boxes.
A cyclic method, this method will work if you have a lower and upper bound, regardless of "regularity":
for el in mySeries: print myDF["name"][(myDF["low"] < el) & (myDF["high"] > el)]
I appreciate that you may not need to loop through a huge series, but at least we do not manually index in the dataframe, which will probably slow down work even more