Python Forum
Python pandas dataframe simulate football points system.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python pandas dataframe simulate football points system.
#1
Hello:
import pandas as pd
import numpy as np

dfGames = pd.DataFrame.from_items([('TeamsHome', ['A', 'B', 'C']), ('TeamsAway', ['B', 'C', 'A']),('Games', [1, 1, 1]), ('HomeGoals', [2, 0, 1]), ('AwayGoals', [0, 0, 2])])
print(dfGames)

dfPoints = pd.DataFrame.from_items([('Teams', ['A', 'B', 'C']),  ('Games', [1, 1, 1]), ('Points', [6, 1, 1])])
print(dfPoints)
Let’s say, we have a small football tournament of 3 teams: A, B and C.
For the first round: A beat B with score, 2:0; B and C had a draw, 0:0; C lost to A, 1:2. The teams and goals are shown in dfGames.
Now, I want to create a dataframe to show each team’s points. The rule is: if the goals are more than the opponent’s goals, then it is a win, which gives the winner 3 points, the loser gets 0 point; if the goals are the same as the opponent’s goals, then it is a draw, each team gets 1 point.
I want to write a function to return a dataframe as dfPoints, I need columns: Teams, Games and Points.
In this example, as team A has 2 wins, therefore, team A has 6 points, team B has one lose, one draw, so it has 1 point, team C is the same as team B.
But I can’t figure this out how to do this using the pandas functions.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HTML Decoder pandas dataframe column mbrown009 3 962 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 1,091 Jan-06-2023, 10:53 PM
Last Post: haihal
  Pandas Dataframe Filtering based on rows mvdlm 0 1,396 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Pandas dataframe: calculate metrics by year mcva 1 2,269 Mar-02-2022, 08:22 AM
Last Post: mcva
  Pandas dataframe comparing anto5 0 1,243 Jan-30-2022, 10:21 AM
Last Post: anto5
  PANDAS: DataFrame | Replace and others questions moduki1 2 1,758 Jan-10-2022, 07:19 PM
Last Post: moduki1
  PANDAS: DataFrame | Saving the wrong value moduki1 0 1,527 Jan-10-2022, 04:42 PM
Last Post: moduki1
  update values in one dataframe based on another dataframe - Pandas iliasb 2 9,100 Aug-14-2021, 12:38 PM
Last Post: jefsummers
  empty row in pandas dataframe rwahdan 3 2,420 Jun-22-2021, 07:57 PM
Last Post: snippsat
Question Pandas - Creating additional column in dataframe from another column Azureaus 2 2,917 Jan-11-2021, 09:53 PM
Last Post: Azureaus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020