T20 World Cup 2022 Analysis using Python

Every sports event generates a lot of data which we can use to analyze the performance of players, teams, and many highlights of the game. As the ICC Men’s T20 world cup has just finished, it has generated a lot of data we can use to summarize the event. So, if you want to learn how to analyze a sports event like the t20 world cup, this article is for you. This article will take you through the task of T20 World Cup 2022 analysis using Python.

T20 World Cup 2022 Analysis using Python

The dataset I am using for the T20 World Cup 2022 analysis is collected manually. You can download the dataset from here.

Now let’s start this task by importing the necessary Python libraries and the dataset:

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import plotly.io as pio
pio.templates.default = "plotly_white"

data = pd.read_csv("t20 world cup 22.csv")
print(data.head())
              venue        team1        team2     stage  toss winner  \
0               SCG  New Zealand    Australia  Super 12    Australia   
1     Optus Stadium  Afghanistan      England  Super 12      England   
2  Blundstone Arena      Ireland    Sri lanka  Super 12      Ireland   
3               MCG     Pakistan        India  Super 12        India   
4  Blundstone Arena   Bangladesh  Netherlands  Super 12  Netherlands   

  toss decision  first innings score  first innings wickets  \
0         Field                200.0                    3.0   
1         Field                112.0                   10.0   
2           Bat                128.0                    8.0   
3         Field                159.0                    8.0   
4         Field                144.0                    8.0   

   second innings score  second innings wickets       winner   won by  \
0                 111.0                    10.0  New Zealand     Runs   
1                 113.0                     5.0      England  Wickets   
2                 133.0                     1.0    Sri lanka  Wickets   
3                 160.0                     6.0        India  Wickets   
4                 135.0                    10.0   Bangladesh     Runs   

  player of the match       top scorer  highest score         best bowler  \
0        Devon Conway     Devon Conway           92.0         Tim Southee   
1          Sam Curran   Ibrahim Zadran           32.0          Sam Curran   
2        Kusal Mendis     Kusal Mendis           68.0  Maheesh Theekshana   
3         Virat Kohli      Virat Kohli           82.0       Hardik Pandya   
4        Taskin Ahmed  Colin Ackermann           62.0        Taskin Ahmed   

  best bowling figure  
0                 3-6  
1                5-10  
2                2-19  
3                3-30  
4                4-25  

Now let’s look at the number of matches won by each team in the world cup:

figure = px.bar(data, 
                x=data["winner"],
                title="Number of Matches Won by teams in t20 World Cup 2022")
figure.show()
t20 World Cup 2022 analysis: Number of Matches Won by teams in t20 World Cup 2022

As England won the t20 world cup 2022, England won five matches. And Both Pakistan and India won 4 matches.

Now let’s have a look at the number of matches won by batting first or second in the t20 world cup 2022:

won_by = data["won by"].value_counts()
label = won_by.index
counts = won_by.values
colors = ['gold','lightgreen']

fig = go.Figure(data=[go.Pie(labels=label, values=counts)])
fig.update_layout(title_text='Number of Matches Won By Runs Or Wickets')
fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=30,
                  marker=dict(colors=colors, line=dict(color='black', width=3)))
fig.show()
Number of Matches Won By Runs Or Wickets in the world cup

So in the t20 world cup 2022, 16 matches were won by batting first, and 13 matches were won by chasing. Now, let’s have a look at the toss decisions by teams in the world cup:

toss = data["toss decision"].value_counts()
label = toss.index
counts = toss.values
colors = ['skyblue','yellow']

fig = go.Figure(data=[go.Pie(labels=label, values=counts)])
fig.update_layout(title_text='Toss Decisions in t20 World Cup 2022')
fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=30,
                  marker=dict(colors=colors, line=dict(color='black', width=3)))
fig.show()
t20 World Cup 2022 analysis: Toss Decisions in t20 World Cup 2022

So in 17 matches, the teams decided to bat first, and in 13 matches, the teams chose to field first. Now let’s have a look at the top scorers in the t20 world cup 2022:

figure = px.bar(data, 
                x=data["top scorer"], 
                y = data["highest score"], 
                color = data["highest score"],
                title="Top Scorers in t20 World Cup 2022")
figure.show()
Top Scorers in t20 World Cup 2022

So, Virat Kohli scored the highest in 3 matches. Undoubtedly, he was the best batsman in the t20 world cup 2022. Now let’s have a look at the number of player of the match awards in the world cup:

figure = px.bar(data, 
                x = data["player of the match"], 
                title="Player of the Match Awards in t20 World Cup 2022")
figure.show()
t20 World Cup 2022 analysis: Player of the Match Awards in t20 World Cup 2022

Virat Kohli, Sam Curran, Taskin Ahmed, Suryakumar Yadav, and Shadab Khan got the player of the match in 2 matches. No player got the player of the match award in more than two matches.

Now let’s have a look at the bowlers with the best bowling figures at the end of the matches:

figure = px.bar(data, 
                x=data["best bowler"],
                title="Best Bowlers in t20 World Cup 2022")
figure.show()
Best Bowlers in t20 World Cup 2022

Sam Curran was the only best bowler in 3 matches. Undoubtedly, he deserved to be the player of the tournament. Now let’s compare the runs scored in the first innings and second innings in every stadium of the t20 world cup 2022:

fig = go.Figure()
fig.add_trace(go.Bar(
    x=data["venue"],
    y=data["first innings score"],
    name='First Innings Runs',
    marker_color='blue'
))
fig.add_trace(go.Bar(
    x=data["venue"],
    y=data["second innings score"],
    name='Second Innings Runs',
    marker_color='red'
))
fig.update_layout(barmode='group', 
                  xaxis_tickangle=-45, 
                  title="Best Stadiums to Bat First or Chase")
fig.show()
Best Stadiums to Bat First or Chase

So SCG was the only stadium in the world cup that was best for batting first. Other stadiums didn’t make much difference while batting first or chasing.

Now let’s compare the number of wickets lost in the first innings and second innings in every stadium of the t20 world cup 2022:

fig = go.Figure()
fig.add_trace(go.Bar(
    x=data["venue"],
    y=data["first innings wickets"],
    name='First Innings Wickets',
    marker_color='blue'
))
fig.add_trace(go.Bar(
    x=data["venue"],
    y=data["second innings wickets"],
    name='Second Innings Wickets',
    marker_color='red'
))
fig.update_layout(barmode='group', 
                  xaxis_tickangle=-45, 
                  title="Best Statiums to Bowl First or Defend")
fig.show()
Best Statiums to Bowl First or Defend

SCG was the best stadium to bowl while defending the target. While the Optus Stadium was the best stadium to bowl first.

Summary

So some highlights of the t20 world cup 2022 we found from our analysis are:

  1. England won the most number of matches
  2. Virat Kohli scored highest in the most number of matches
  3. Sam Curran was the best bowler in the most number of matches
  4. More teams won by batting first
  5. More teams decided to bat first
  6. SCG was the best stadium to bat first
  7. SCG was the best stadium to defend the target in the World Cup
  8. The Optus Stadium was the best stadium to bowl first

I hope you liked this article on the t20 world cup 2022 analysis using Python. Feel free to ask valuable questions in the comments section below.

Aman Kharwal
Aman Kharwal

Coder with the ♥️ of a Writer || Data Scientist | Solopreneur | Founder

Articles: 1333

Leave a Reply