Learn practical skills, build real-world projects, and advance your career
import pandas as pd
import numpy as np
players=pd.read_excel("C:\\Users\\debje\\Desktop\\PYTHON\\EDA\\IPL Data\\Player.xlsx")
ball=pd.read_excel("C:\\Users\\debje\\Desktop\\PYTHON\\EDA\\IPL Data\\Ball_by_Ball.xlsx")
match=pd.read_excel("C:\\Users\\debje\\Desktop\\PYTHON\\EDA\\IPL Data\\Match.xlsx")
team=pd.read_excel("C:\\Users\\debje\\Desktop\\PYTHON\\EDA\\IPL Data\\Team.xlsx")
season=pd.read_excel("C:\\Users\\debje\\Desktop\\PYTHON\\EDA\\IPL Data\\Season.xlsx")
player_match=pd.read_excel("C:\\Users\\debje\\Desktop\\PYTHON\\EDA\\IPL Data\\Player_Match.xlsx")
ball.dtypes
Match_Id                     int64
Season_Id                    int64
Innings_Id                   int64
Over_Id                      int64
Ball_Id                      int64
Team_Batting_Id              int64
Team_Bowling_Id              int64
Striker_Id                   int64
Striker_Batting_Position     int64
Non_Striker_Id               int64
Bowler_Id                    int64
Batsman_Scored               int64
Extra_Type                  object
Extra_Runs                  object
Player_dissimal_Id          object
Dissimal_Type               object
Fielder_Id                  object
dtype: object
cols1 = [cols1 for cols1 in ball.columns if (cols1!= "Batsman_Scored") and (cols1!="Extra_Runs")]

ball[cols1]= ball[cols1].apply(lambda x: x.astype("category"))
ball.dtypes
Match_Id                    category
Season_Id                   category
Innings_Id                  category
Over_Id                     category
Ball_Id                     category
Team_Batting_Id             category
Team_Bowling_Id             category
Striker_Id                  category
Striker_Batting_Position    category
Non_Striker_Id              category
Bowler_Id                   category
Batsman_Scored                 int64
Extra_Type                  category
Extra_Runs                    object
Player_dissimal_Id          category
Dissimal_Type               category
Fielder_Id                  category
dtype: object
import matplotlib.pyplot as plt

run_by_innings=ball.pivot_table(index="Innings_Id" ,values="Batsman_Scored", aggfunc=np.sum).reset_index()
final2=pd.DataFrame()
first=run_by_innings[(run_by_innings["Innings_Id"] == 1) | (run_by_innings["Innings_Id"] == 3)]["Batsman_Scored"].sum()
second=run_by_innings[(run_by_innings["Innings_Id"] == 2) | (run_by_innings["Innings_Id"] == 4)]["Batsman_Scored"].sum()

innings=["first_innings","second_innings"]
runs= [first,second]
final2["Innings"]=innings
final2["Runs"]=runs
final2.set_index("Innings",inplace=True)
final2.plot(kind="bar",use_index="Innings")
plt.xticks(rotation=45)
plt.ylabel("Runs")
plt.show()
Notebook Image