Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created February 8, 2021 09:52
Show Gist options
  • Save amankharwal/d03c6c33302d9b1af79b094570d91210 to your computer and use it in GitHub Desktop.
Save amankharwal/d03c6c33302d9b1af79b094570d91210 to your computer and use it in GitHub Desktop.
#Create Age segment
cut_labels_Age = ['Young', 'Adult', 'Mature', 'Senior']
cut_bins = [0, 30, 45, 65, 120]
data['Age_group'] = pd.cut(data['Age'], bins=cut_bins, labels=cut_labels_Age)
#Create Income segment
cut_labels_Income = ['Low income', 'Low to medium income', 'Medium to high income', 'High income']
data['Income_group'] = pd.qcut(data['Income'], q=4, labels=cut_labels_Income)
#Create Seniority segment
cut_labels_Seniority = ['New customers', 'Discovering customers', 'Experienced customers', 'Old customers']
data['Seniority_group'] = pd.qcut(data['Seniority'], q=4, labels=cut_labels_Seniority)
data=data.drop(columns=['Age','Income','Seniority'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment