Skip to content

Instantly share code, notes, and snippets.

@amrakm
Created October 29, 2018 23:43
Show Gist options
  • Save amrakm/24f7b459a006629c3e53f1cb55e24962 to your computer and use it in GitHub Desktop.
Save amrakm/24f7b459a006629c3e53f1cb55e24962 to your computer and use it in GitHub Desktop.
ranges = [0,50,100,160]
ranges_label = ['cheap', "average", "expensive"]
df['price_cat'] = pd.cut(df.current_package_price, ranges, labels=ranges_label)
# Another example
# Bucketing age groups
ranges = [18,25,29,34, 50,70, 2020]
ranges_label = ['18-25','26-29',"30-34", "35-50", '51-70','unknown']
df['age_group'] = pd.cut(df['age'], ranges, labels=ranges_label)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment