1test = pd.DataFrame({'days': [0,20,30,31,45,60]})
2
3test['range1'] = pd.cut(test.days, [0,30,60], include_lowest=True)
4#30 value is in [30, 60) group
5test['range2'] = pd.cut(test.days, [0,30,60], right=False)
6#30 value is in (0, 30] group
7test['range3'] = pd.cut(test.days, [0,30,60])
8print (test)
9 days range1 range2 range3
100 0 (-0.001, 30.0] [0, 30) NaN
111 20 (-0.001, 30.0] [0, 30) (0, 30]
122 30 (-0.001, 30.0] [30, 60) (0, 30]
133 31 (30.0, 60.0] [30, 60) (30, 60]
144 45 (30.0, 60.0] [30, 60) (30, 60]
155 60 (30.0, 60.0] NaN (30, 60]
1>>> pd.qcut(range(5), 3, labels=["good", "medium", "bad"])
2...
3[good, good, medium, bad, bad]
4Categories (3, object): [good < medium < bad]
5