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

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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)
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.
I actualized it, please let me know if what you get is now fine. B

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.