I have a DataFrame with columnA
with integer values that range between -3 and 89.
I want to select all the rows with values in columnA
between discrete 10 unit bins, e.g.
-10 to 0
0 to 10 ...
80 to 90
I can produce a list of the number of rows in each bin like this:
pd.cut(DataFrame['columnA'], np.arange(-10, 100, 10), include_lowest=True, labels=False).value_counts().sort_index().to_list()
resulting in a list like this:
[505, 25000, 21, 393, 79232, 953000, 24121, 662, 50, 900]
Now if I want to examine all the rows in the first bin, I can select them like this:
DataFrame.sort_values('columnA', ascending=True).iloc[0:505]
How can I write a function to select all the rows in bin N?