'How do I fix the if condition?

I want to satisfy all the following conditions but Yr1,Yr2 and Yr3 are not columns. It is excel sheet names.

if df["Grades"]>="D": and Yr1>=27 and Yr2>=27 and (Yr1+Yr2) >=60 and Yr3>=27:
    print("True")

error shows

Invalid comparison between dtype=float64 and str

how do i fix this.



Solution 1:[1]

I think the value of "df["Grades"]" is in float. But in the condition, you are using string. Try something like this,

if df["Grades"]>=1.00 and Yr1>=27 and Yr2>=27 and (Yr1+Yr2) >=60 and Yr3>=27:
    print("True")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aman Gondaliya