0

I have a dataframe with 10,000 ages that I want to group by these groups

def age1(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'

I tried an For loop and a lambda function:

map(lambda x : "18-29" if (x >= 18) and (x < 30) else "other",[1,10,20,30]) 

but nothing runs!

I am having trouble and getting many errors like these: TypeError: 'DataFrame' object is not callable

My dataframe consists of two columns I pulled from my main dataframe and looks like this:

    Age Exited
0   42  1
1   41  0
2   42  1
3   39  0
4   43  0

What I want is another column Entitled "Ages by Group" so what is the most efficient way to perform this?

0 Answers0