Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- df['new_col'] = pd.cut(df['existing_col'],
- bins=[1, 5, 12, 18, 24, 30, np.inf], # bins = ranges ie 1, 5 = 1 to 5
- labels=['1 to 5', '5 to 12', '12 to 18', # labels map to the bin ranges ie: 1, 5 = '1 to 5'
- '18 to 24', '24 to 30', '>30'],
- right=False)
- # If you're going to use cut use np.inf not an arbitrary upper bound value of 999999. OP's function is also lowerbound inclusive so need right=False
Advertisement
Add Comment
Please, Sign In to add comment