Working with a dataframe that looks like this (text version below):
I am supposed to calculate which country has scored the most goals since 2010 in tournaments. So far I have managed to manipulate the dataframe by filtering out friendlies like this:
no_friendlies = df[df.tournament != "Friendly"]
Then I set the date column to be the index in order to filter out all matches before 2010:
no_friendlies_indexed = no_friendlies.set_index('date')
since_2010 = no_friendlies_indexed.loc['2010-01-01':]
I am pretty lost from this point onward as I can't figure out how to sum goals scored by each country both home and away
Any help/advice is appreciated!
EDIT:
Text version of sample data:
date home_team away_team home_score away_score tournament city country neutral
0 1872-11-30 Scotland England 0 0 Friendly Glasgow Scotland False
1 1873-03-08 England Scotland 4 2 Friendly London England False
2 1874-03-07 Scotland England 2 1 Friendly Glasgow Scotland False
3 1875-03-06 England Scotland 2 2 Friendly London England False
4 1876-03-04 Scotland England 3 0 Friendly Glasgow Scotland False
5 1876-03-25 Scotland Wales 4 0 Friendly Glasgow Scotland False
6 1877-03-03 England Scotland 1 3 Friendly London England False
7 1877-03-05 Wales Scotland 0 2 Friendly Wrexham Wales False
8 1878-03-02 Scotland England 7 2 Friendly Glasgow Scotland False
9 1878-03-23 Scotland Wales 9 0 Friendly Glasgow Scotland False
10 1879-01-18 England Wales 2 1 Friendly London England False
EDIT 2:
I have just tried doing this:
since_2010.groupby(['home_team', 'home_score']).sum()
But it doesn't return the sum of home goals scored by the home teams (if this worked i would just repeat it for away teams to get total)
['date', 'team', 'Home_or_Away', 'score']
.pd.wide_to_long
ormelt
can accomplish that. – Ravishment.groupby
theTeam_name
and get thesum()
of theScore
. – Quantify