Soln
Soln
3. What is the average number of runs by which teams win in each season?
python
Copy
average_runs_by_season =
df.groupby('season')['win_by_runs'].mean().reset_index(name='average_runs_won
')
print(average_runs_by_season)
4. Which player won the most "Player of the Match" awards in 2017?
python
Copy
player_of_the_match_2017 = df[df['season'] ==
2017].groupby('player_of_match').size().reset_index(name='awards')
player_of_the_match_2017 = player_of_the_match_2017.sort_values(by='awards',
ascending=False)
print(player_of_the_match_2017.head(1))
5. How many matches did each team win at home (based on the venue)?
python
Copy
team_home_wins = df.groupby(['team1', 'venue'])['winner'].apply(lambda x: (x
== x.name).sum()).reset_index(name='home_wins')
print(team_home_wins)
10. Which team had the highest average number of runs won by in 2017?
python
Copy
avg_runs_by_team_2017 = df[df['season'] ==
2017].groupby('team1')['win_by_runs'].mean().reset_index(name='avg_runs_won')
avg_runs_by_team_2017 = avg_runs_by_team_2017.sort_values(by='avg_runs_won',
ascending=False)
print(avg_runs_by_team_2017.head(1))
11. What is the total number of wins by wickets for each team in 2017?
python
Copy
wins_by_wickets_2017 = df[df['season'] ==
2017].groupby('team1')['win_by_wickets'].sum().reset_index(name='total_wicket
s_won')
print(wins_by_wickets_2017)
13. How many times did each team win by 0 runs in 2017?
python
Copy
team_zero_runs_wins = df[(df['season'] == 2017) & (df['win_by_runs'] ==
0)].groupby('team1').size().reset_index(name='wins_by_zero_runs')
print(team_zero_runs_wins)
15. What was the total number of runs and wickets won by each team?
python
Copy
team_runs_and_wickets = df.groupby('team1').agg({'win_by_runs': 'sum',
'win_by_wickets': 'sum'}).reset_index()
print(team_runs_and_wickets)