Вы можете попробовать с pandas.cut
: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.cut.html
import pandas as pd
import numpy as np
df=pd.DataFrame({"age": [4, 23, 45, 39, 76, 91, 110, 10], "x": [1,2,1,5,2,8,1,1]})
print(pd.merge(df, pd.cut(df["age"],bins=pd.IntervalIndex.from_tuples([(0, 10), (11, 20), (21, 30),(31,40),(41,50),(51,60),(61,70),(71,80),(81,90),(90, np.Infinity)]),right=True, include_lowest=True), left_index=True, right_index=True, how="outer", suffixes=["", "_bins"]))
Вывод:
age x age_bins
0 4 1 (0.0, 10.0]
1 23 2 (21.0, 30.0]
2 45 1 (41.0, 50.0]
3 39 5 (31.0, 40.0]
4 76 2 (71.0, 80.0]
5 91 8 (90.0, inf]
6 110 1 (90.0, inf]
7 10 1 (0.0, 10.0]
[Program finished]