I'm using pandas and my data frame goes like this:
Unnamed: 0 id player_name games time goals xG \
0 0 647 Harry Kane 35 3097 23 22.174859
1 1 1250 Mohamed Salah 37 3085 22 20.250847
2 2 1228 Bruno Fernandes 37 3117 18 16.019454
3 3 453 Son Heung-Min 37 3139 17 11.023287
4 4 822 Patrick Bamford 38 3085 17 18.401863
.. ... ... ... ... ... ... ...
assists xA shots key_passes yellow_cards red_cards position \
0 14 7.577094 138 49 1 0 F
1 5 6.528526 126 55 0 0 F M S
2 12 11.474996 121 95 6 0 M S
3 10 9.512992 68 75 0 0 F M S
4 7 3.782247 107 30 3 0 F S
.. ... ... ... ... ... ... ...
team_title npg npxG xGChain xGBuildup
0 Tottenham 19 19.130183 24.995648 4.451257
1 Liverpool 16 15.683834 28.968234 9.800236
2 Manchester United 9 8.407840 26.911412 11.932285
3 Tottenham 16 10.262118 20.671916 6.608751
4 Leeds 15 16.879525 23.394953 4.131796
.. ... ... ... ... ...
I'm trying to group it by team_title and sort it by goals and assists
in which will become something like this:
team_title player_name goals assists
Tottenham Harry Kane 23 14
Tottenham Gareth Bale ... ...
Tottenham Son Heung-Min ... ...
I've tried using
if any('Tottenham' in db['team_title']):
db.groupby('team_title')['player_name',''goals','assists'].value_counts()
and the error message I'm getting is
TypeError: 'bool' object is not iterable
is it correct using if-else or are there any other way to sort from specific value of string?
if any('Tottenham' in db['team_title'])?anyneeds an iterable as argument.