Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

add age categories pandas dataframe


X_train_data = pd.DataFrame({'Age':[0,2,4,13,35,-1,54]})

bins= [0,2,4,13,20,110]
labels = ['Infant','Toddler','Kid','Teen','Adult']
X_train_data['AgeGroup'] = pd.cut(X_train_data['Age'], bins=bins, labels=labels, right=False)
print (X_train_data)
   Age AgeGroup
0    0   Infant
1    2  Toddler
2    4      Kid
3   13     Teen
4   35    Adult
5   -1      NaN
6   54    Adult

Comment

PREVIOUS NEXT
Code Example
Python :: how to find magnitude of complex number in python 
Python :: python date from string 
Python :: isidentifier method in python 
Python :: upgrade python wsl 
Python :: sum of all multiples of 3 and 5 below 100 
Python :: python space separated input 
Python :: python dict sort by value 
Python :: count values in numpy list python 
Python :: how to make a class in python 
Python :: python - count values that contain special characters 
Python :: python dictionary comprehension 
Python :: python list to bytes 
Python :: how to display address in python 
Python :: pywhatkit 
Python :: pep full form 
Python :: count occurrences of value in array python 
Python :: how to change os path in python 
Python :: word generator in python 
Python :: how to count the number of files in a directory using python 
Python :: scanner class in python 
Python :: how to make calculator in python 
Python :: how to use inverse trigonometric functions in python 
Python :: django template for loop 
Python :: adf test python 
Python :: how to count unique values in dataframe df python 
Python :: sklearn cross_val_score scoring metric 
Python :: delete directory if exists python 
Python :: sort rows in csv file using python pandas 
Python :: check input in python 
Python :: random question generator python 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =