I have this code written down which returns a bunch of ratios each line works fine when executed alone however I am having trouble with putting the code inside a function which should return the values as a dictionary
example of the output: { " less than high school" :0.2 , "high school" :0.39 ...}
def education ():
total = sum (df["CHILDNM"])
edult12 = df[['EDUC1','CHILDNM']].where(df['EDUC1'] == 1, 0)
nlt12=sum( edult12["CHILDNM"])
edu12 = df[['EDUC1','CHILDNM']].where(df['EDUC1'] == 2, 0)
n12= sum( edu12["CHILDNM"])
edumt12 = df[['EDUC1','CHILDNM']].where(df['EDUC1'] == 3, 0)
nmt12=sum( edumt12["CHILDNM"])
educollege = df[['EDUC1','CHILDNM']].where(df['EDUC1'] == 4, 0)
ncollege = sum( educollege["CHILDNM"])
lt12ratio = nlt12/total
edu12ratio = n12 / total
edumt12ratio = nmt12 / total
educollegeratio = ncollege/total
values = print (lt12ratio, edu12ratio,edumt12ratio, educollegeratio )
print (values)