Skip to content
Advertisement

Python if statement not working correctly and no idea why

In my code I iterate through dataframes of each year to calculate the number of wins (increase between numbers) and losses (decrease between numbers), and the ratio of wins to losses. The loop I run correctly displays the right number of wins and losses in the dataframe they are eventually pushed to. However, when calculating the win/loss ratio, the if statement isn’t working for no real reason. Here is the loop:

JavaScript

Here is the outcome in the Dataframe:

JavaScript

As you can see it works on one or two but fails on the most, making most of them wins?

Advertisement

Answer

I believe you should be using “and” instead of “&” in the if statements. You can read up on the differences here:

https://www.geeksforgeeks.org/difference-between-and-and-in-python/

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement