I have a column of age values that I need to convert to age ranges of 18-29, 30-39, 40-49, 50-59, 60-69, and 70+:
For an example of some of the data in df \'file\',
A friend came up with this response offline that works: def age_buckets(x): if x < 30: return '18-29' elif x < 40: return '30-39' elif x < 50: return '40-49' elif x < 60: return '50-59' elif x < 70: return '60-69' elif x >=70: return '70+' else: return 'other'
file['agerange'] = file.age.apply(age_buckets)
Thanks to everyone who took a crack at this!