Reputation: 63
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']
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
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
Upvotes: 1
Views: 78
Reputation: 893
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.
Upvotes: 1