Hello I would like to sort the Bundesliga table according to the points of each team not by the team name. Can someone help me? Currently I can sort the issue only by team name. I don't know how to sort the points after the for-loop.
def push2(self):
#Download Database
urllib.request.urlretrieve(
"http://www.football-data.co.uk/mmz4281/1819/d1.csv",
"2018-19.csv")
#Read Database
df = pd.read_csv("2018-19.csv")
teams = df["HomeTeam"]
teams = teams.drop_duplicates()
teams = teams.sort_values(0, False, False)
teams = teams.tolist()
namesLen = len(teams)
for i in range(0, namesLen):
# Get points through victories
team = df[(df["HomeTeam"] == teams[i]) | (
df["AwayTeam"] == teams[i])]
teamWin = team[((team["FTR"] == "H") & (
team["HomeTeam"] == teams[i])) | (
(team["FTR"] == "A") & (
team["AwayTeam"] == teams[
i]))]
teamTotalPoints = (len(teamWin.index) * 3)
# Get points through draw
teamU = df[(df["HomeTeam"] == teams[i]) | (
df["AwayTeam"] == teams[i])]
teamD = teamU[(team["FTR"] == "D")]
teamDTotal = (len(teamD.index) * 1)
# Total points wins and points draws
teamT = teamTotalPoints + teamDTotal
teamTStr = str(teamT)
print(str( teamTStr + ": " +teams[i] ))