'Python: Can't convert str to int after loading from .csv file

I've loaded a .csv file into my code and I'm trying to compare scores. Most of the time, Python reads the code correctly (as in the bigger score is greater than the smaller score). But when I'm dealing with 1 digit vs. 2, Python will actually count the smaller score as the greater one (ex: 3 > 17). I know that it's doing it wrong because I attached a counter in order to count wins.

with open(path + file_name, 'rt') as csv_file:
  NFL_stats = csv.DictReader(csv_file)

  season_year = input("Pick a year after 1966: ")
  team = input("Pick a team: ")
  wins = int(0)
  
  for current_row in NFL_stats:
    if current_row["schedule_season"] == season_year:
      home = current_row["team_home"],current_row["score_home"]
      away = current_row["team_away"],current_row["score_away"]
      if team==home[0]:
        my_team = home
        other_team = away
      elif team==away[0]:
        my_team = away
        other_team = home
      else:
        continue
      print(*home,*away)
      if my_team[1]>other_team[1]:
        print("Win!")
      elif my_team[1]<other_team[1]:
        print("Loss.")

  print(wins)

I've been using the Buffalo Bills 2021 season as my example. The code gives me the correct answer for every game except for Week 12 (@NO) because the score ended 6 - 31. According to the code, 6 > 31.

I've looked at a bunch of different answers on the internet on how to change the entire column of "score_home" and "score_away" into integer but nothing has worked so far. I even attempted to change the columns in the .csv file in Excel using VBM but that also didn't change my issue. Can someone help me?



Solution 1:[1]

Use int() to covert from string to integer.

Corrected code:

 if int(my_team[1])>int(other_team[1]):
    print("Win!")
 elif int(my_team[1])<int(other_team[1]):
    print("Loss.")

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 thirdsandfourths