I am getting an error of - 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 when trying to run a simple loop. How can it be corrected?
for i in range(0,df.shape[0] 1):
if(df.iloc[i,8] >= 90):
df.iloc[i,9]="Ex"
elif (df.iloc[i,8] >= 80 & df.iloc[i,8] <90):
df.iloc[i,9]="A"
elif(df.iloc[i,8] >= 70 & df.iloc[i,8] <80):
df.iloc[i,9]="B"
elif(df.iloc[i,8] >= 60 & df.iloc[i,8] <70):
df.iloc[i,9]="C"
elif(df.iloc[i,8] >= 50 & df.iloc[i,8] <60):
df.iloc[i,9]="D"
else:
df.iloc[i,9]="E"
CodePudding user response:
I assume you're trying to AND the bools? This is an issue of operator precedence. Bitwise AND is higher precedence than comparison operators so your code is trying to do 70 & df.iloc[i,8]
first, which would be an issue depending on the type stored in df
CodePudding user response:
Sorry, I solved the question. Only bracket has to be assigned.
for i in range(0,df.shape[0] 1):
if(df.iloc[i,8] >= 90):
df.iloc[i,9]="Ex"
elif ((df.iloc[i,8] >= 80) & (df.iloc[i,8] <90)):
df.iloc[i,9]="A"
elif((df.iloc[i,8] >= 70) & (df.iloc[i,8] <80)):
df.iloc[i,9]="B"
elif((df.iloc[i,8] >= 60) & (df.iloc[i,8] <70)):
df.iloc[i,9]="C"
elif((df.iloc[i,8] >= 50) & (df.iloc[i,8] <60)):
df.iloc[i,9]="D"
else:
df.iloc[i,9]="E"