I'm trying to write an if, elif function to determine a student's college selectivity based on their GPA and SAT score. My dataframe has the students' names as the index, their GPA, and their SAT score. I want to create a new column that states their selectivity. I thought at first I was messing up my and vs &, but have tried it a few different ways and keep getting: TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''.
Here is my code:
def f(x):
if x['GPA W'] < 2.0 & x['SAT'] == NaN:return "2 yr"
elif x['GPA W'] < 2.0 & x['SAT'] < 940:return "2 yr"
elif x['GPA W'] < 2.0 & x['SAT'] >= 940 & x['SAT']<= 1050: return "Non-Selective 4 yr"
elif x['GPA W'] < 2.0 & x['SAT'] >= 1060 & x['SAT']<= 1150:return "Somewhat Selective"
elif x['GPA W'] < 2.0 & x['SAT'] >=1160:return "Somewhat Selective"
elif x['GPA W'] >= 2.0 and x['GPA W']<=2.4 & x['SAT'] == NaN:return "Non-Selective 4 yr"
elif x['GPA W'] >= 2.0 and x['GPA W']<=2.4 & x['SAT'] < 940:return "Non-Selective 4 yr"
elif x['GPA W'] >= 2.0 and x['GPA W']<=2.4 & x['SAT'] >= 940 and x['SAT'] <= 1050:return "Somewhat Selective"
elif x['GPA W'] >= 2.0 and x['GPA W']<=2.4 & x['SAT'] >= 1060 and x['SAT']<= 1150:return "Somewhat Selective"
elif x['GPA W'] >= 2.0 and x['GPA W']<=2.4 & x['SAT'] > 1160:return "Selective/Very Selective"
elif x['GPA W'] >= 2.5 and x['GPA W']<=2.9 & x['SAT'] == NaN:return "Somewhat Selective"
elif x['GPA W'] >= 2.5 and x['GPA W']<=2.9 & x['SAT'] < 940:return "Somewhat Selective"
elif x['GPA W'] >= 2.5 and x['GPA W']<=2.9 & x['SAT'] >= 940 and x['SAT']<= 1050:return "Somewhat Selective"
elif x['GPA W'] >= 2.5 and x['GPA W']<=2.9 & x['SAT'] >= 1060 and x['SAT']<= 1150:return "Selective"
elif x['GPA W'] >= 2.5 and x['GPA W']<=2.9 & x['SAT'] > 1160:return "Selective/Very Selective"
elif x['GPA W'] >= 3.0 and x['GPA W']<=3.4 & x['SAT'] == NaN:return "Selective"
elif x['GPA W'] >= 3.0 and x['GPA W']<=3.4 & x['SAT'] < 940:return "Somewhat Selective"
elif x['GPA W'] >= 3.0 and x['GPA W']<=3.4 & x['SAT'] >= 940 and x['SAT']<= 1050:return "Selective"
elif x['GPA W'] >= 3.0 and x['GPA W']<=3.4 & x['SAT'] >= 1060 and x['SAT']<= 1150:return "Selective/Very Selective"
elif x['GPA W'] >= 3.0 and x['GPA W']<=3.4 & x['SAT'] > 1160:return "Very Selective"
elif x['GPA W'] >= 3.5 and x['GPA W']<=4.0 & x['SAT'] == NaN:return "Selective"
elif x['GPA W'] >= 3.5 and x['GPA W']<=4.0 & x['SAT'] < 940:return "Selective"
elif x['GPA W'] >= 3.5 and x['GPA W']<=4.0 & x['SAT'] >= 940 and x['SAT']<= 1050:return "Selective/Very Selective"
elif x['GPA W'] >= 3.5 and x['GPA W']<=4.0 & x['SAT'] >= 1060 and x['SAT']<= 1150:return "Selective/Very Selective"
elif x['GPA W'] >= 3.5 and x['GPA W']<=4.0 & x['SAT'] > 1160:return "Very Selective"
else:return "Unknown"
dat['Selectivity'] = dat.apply(f, axis=1)