1

I have a random data set which is the 2018/2019 football season

data = pd.DataFrame({'HomeTeam': ['Marseille', 'Toulouse', 'Angers', 'Nimes','Paris'...], 
'FTR': ["H", "A", "D"],'FTRNUM': ["1", "2", "3"]})

I made 'FTRNUM' to get a number according to FTR : 1 equals to ['FTR' = 'H'] 2 equals to ['FTR' = 'A'] and 3 equals to ['FTR' = 'D']

dataset

I'm trying to make random statistics with it.

How can I get for exemple the win number of a specific team in ['HomeTeam'] according to ['FTR'] or ['FTRNUM']. (FTR = Full Time Result).

I'm doing it with :

data9 = data.groupby('HomeTeam')['FTRNUM'].value_counts().to_frame()
data9

enter image description here

And adding it manually with number but How can I simply catch this number instead of adding it manually ?

The value would be for everything in HomeTeam How many time Paris SG appears with FTR = "H".

The final result would be something like this

n_matchwinPSGDOM = 17
win_ratewinPSGDOM = (float(n_matchwinPSGDOM) / (n_paris)) * 100
print ("PARIS won Home 
 {:.2f}%".format(win_ratewinPSGDOM),"matchs")

But not with a manually 17.

I will appreciate your help.

B

Bruno93600
  • 53
  • 8
  • Hello, please provide a [reproducible example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). The screenshot is not reproducible. – Steele Farnsworth Nov 14 '21 at 20:53

1 Answers1

1
home_paris: int = data['HomeTeam'].value_counts().get('Paris SG')
away_paris: int = data['AwayTeam'].value_counts().get('Paris SG')
total_paris = home_paris + away_paris

Please let me know if this is not what was wanted.

Steele Farnsworth
  • 863
  • 1
  • 6
  • 15
  • Thanks ! But this one gave me the number of matchs played by Paris as I did with : n_paris = len(data[data.HomeTeam == 'Paris SG']) n_paris2= len(data[data.AwayTeam == 'Paris SG']) n_PSG = n_paris + n_paris2 I need to catch the number of win that we can have according to 'FTR' (H= HomeTeam won, A=AwayTeam won, D= Draw) – Bruno93600 Nov 14 '21 at 21:00
  • 1
    I am sorry that this does not answer the question. I am happy to further assist once you provide a reproducible example per the instructions in my comment to the original post. – Steele Farnsworth Nov 14 '21 at 21:02
  • I actualized it, please let me know if what you get is now fine. B – Bruno93600 Nov 14 '21 at 21:12