1

I have an IPL Data Set called matches.csv which I am fetching from Kaggle, from where I am trying to find out the place where the maximum number of matches were played.

The below code is giving me the correct value for the number of matches played, but I would like to check the Name of the Stadium where the maximum number of matches were played.

matches['venue'].value_counts().max()

This gives me 66

Expected Output is to be like:

M Chinnaswamy Stadium     66

Also if it is possible I would like to get all the details of the last match that was played in that Stadium.

Below is the head of the dataframe:

    id  season  city    date    team1   team2   toss_winner toss_decision   result  dl_applied  winner  win_by_runs win_by_wickets  player_of_match venue   umpire1 umpire2 umpire3
0   1   2017    Hyderabad   2017-04-05  Sunrisers Hyderabad Royal Challengers Bangalore Royal Challengers Bangalore field   normal  0   Sunrisers Hyderabad 35  0   Yuvraj Singh    Rajiv Gandhi International Stadium, Uppal   AY Dandekar NJ Llong    NaN
1   2   2017    Pune    2017-04-06  Mumbai Indians  Rising Pune Supergiant  Rising Pune Supergiant  field   normal  0   Rising Pune Supergiant  0   7   SPD Smith   Maharashtra Cricket Association Stadium A Nand Kishore  S Ravi  NaN
2   3   2017    Rajkot  2017-04-07  Gujarat Lions   Kolkata Knight Riders   Kolkata Knight Riders   field   normal  0   Kolkata Knight Riders   0   10  CA Lynn Saurashtra Cricket Association Stadium  Nitin Menon CK Nandan   NaN
5
  • Possible duplicate of Find maximum value of a column and return the corresponding row values using Pandas Commented Jan 6, 2019 at 14:38
  • @busybear, I dont think it's exactly a duplicate. Here he wants the max row from value_counts(). Do you agree? Commented Jan 6, 2019 at 14:41
  • @najeem Yes, but the value_counts result is still a dataframe. Although I did just notice the last bit where OP asks for information from the last match, which would require a bit more information as you pointed out. Commented Jan 6, 2019 at 14:45
  • @jezrael can we have this open now? Commented Jan 7, 2019 at 18:21
  • 1
    @anky_91 I cannot do it, only moderator. Vote for opening. Commented Jan 7, 2019 at 20:22

2 Answers 2

2

Find out the place where the maximum number of matches were played

>>matches['venue'].value_counts().head(1)
M Chinnaswamy Stadium    66

Note that value_counts already sorts the data in a descending manner, so the first record is always the maximum.

Get all the details of the last match that was played in that Stadium.

>>matches[matches['venue']=='M Chinnaswamy Stadium'].sort_values('date',ascending=False).head(1)

    id  season  city    date    team1   team2   toss_winner toss_decision   result  dl_applied  winner  win_by_runs win_by_wickets  player_of_match venue   umpire1 umpire2 umpire3
57  58  2017    Bangalore   2017-05-19  Kolkata Knight Riders   Mumbai Indians  Mumbai Indians  field   normal  0   Mumbai Indians  0   6   KV Sharma   M Chinnaswamy Stadium   NJ Llong    Nitin Menon NaN

Here you can make a slice of the dataframe by querying the venue name, and then sort_values on the date column putting ascending=False and getting the first result, which gives you the latest match details.

Note I have used the latest kaggle dataset. The values might have changed, but the solution remains same.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Move the value_counts() to a new variable and then you can extract a subset of that data.

vmax = matches['venue'].value_counts()
vmax[vmax == vmax.max()]

Also if it is possible I would like to get all the details of the last match that was played in that Stadium.

For this, you need to post sample of the dataset.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.