1
df=pd.read_csv('./ipl/all_matches.csv')
df1=df[['match_id','season','venue','innings','striker','bowler','batting_team','bowling_team','ball','runs_off_bat','extras']]

df1=df1.loc[(df1['ball'] < 6.1)]
df1['total'] = df1['runs_off_bat'] + df1['extras']

my dataframe

The data frame should look like

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • you want to group by the match id and sum the runs. have a look at: [pandas groupby and sum](https://stackoverflow.com/q/39922986/13138364) – tdy May 01 '21 at 08:00
  • Does this answer your question? [Pandas group-by and sum](https://stackoverflow.com/questions/39922986/pandas-group-by-and-sum) – bad_coder May 02 '21 at 09:35

1 Answers1

0

Few changes that I've made:

  1. Specify the columns that you wanna read in the pd.read_csv args.
  2. groupby match_id and aggregated the sum of the total column for each group.
use_col = ['match_id','season','venue','innings','striker','bowler','batting_team','bowling_team','ball','runs_off_bat','extras']
df=pd.read_csv('./ipl/all_matches.csv', usecols= use_col)

df1=df1.loc[(df1['ball'] < 6.1)]
df1['total'] = df1['runs_off_bat'] + df1['extras']
total_run_per_match = df1.groupby('match_id').agg({'total': sum})

If you wanna preserve the original data frame:

df1['total_run_per_match'] = df1.groupby('match_id')['transform'].sum()
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Nk03
  • 14,699
  • 2
  • 8
  • 22