I have a pandas dataframe and I want to create categories in a new column based on the values of another column. I can solve my basic problem by doing this:
range = {
range(0, 5) : 'Below 5',
range(6,10): 'between',
range(11, 1000) : 'above'
}
df['range'] = df['value'].map(range)
In the final dictionary key I have chosen a large upper value for range to ensure it captures all the values I am trying to map. However, this seems an ugly hack and am wondering how to generalise this without specifying the upper limit. ie. if > 10 : 'above'.
Thanks