Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Fill column based on values of another column

conditions = [
    (df['Age'] < 20),
    (df['Age'] >= 20) & (df['Age'] < 40),
    (df['Age'] >= 40) & (df['Age'] < 59),
    (df['Age'] >= 60)
]

values = ['<20 years old', '20-39 years old', '40-59 years old', '60+ years old']

df['Age Group'] = np.select(conditions, values)

print(df)
Source by datagy.io #
 
PREVIOUS NEXT
Tagged: #Fill #column #based #values #column
ADD COMMENT
Topic
Name
3+5 =