1

I have a dataframe that currently looks like this.

    season  date        winner
59  2008    2008-04-18  KKR
60  2008    2008-04-19  CSK
61  2008    2008-04-19  DC
62  2008    2008-04-20  RCB
63  2008    2008-04-20  KKR
64  2008    2008-04-21  RR

There is a date column with the dates and a winner column with the name of the team that won on that date.

I am trying to make a bar chart race. For that, I need to to get the data for every single date separately, where each date has all the teams and the number of wins of those teams till that date.

I have arranged the date in a sorted manner and added a column where I have grouped the data by the "winner" column and used the cumcount function to get the cumulative count.

df["col"]=df.groupby(["winner"]).cumcount()+1

Now, it looks like this.

    season  date        winner  col
59  2008    2008-04-18  KKR     1
60  2008    2008-04-19  CSK     1
61  2008    2008-04-19  DC      1
62  2008    2008-04-20  RCB     1
63  2008    2008-04-20  KKR     2
64  2008    2008-04-21  RR      1

For any date, I have the data for the winner on that day, but I don't know how to get the data for the other teams on that date.

I have also looked at this answer but here the values not present in the name column on a particular day don't need to be used.

Basically, I need a function where I pass the date and I get the no of wins for each team till that date.

Any help would be greatly appreciated.

  • 2
    Please provide sample data as text, not as picture. – Henry Yik Jul 17 '20 at 09:30
  • @ApocalypticWarrior could you please show how your expected output should look like? I didn't understand it from your question – Ric S Jul 19 '20 at 10:47
  • @RicS I found out a simple way of doing it using the get_dummies method and joining the dataframe. Thanks for the help, though. – Apocalyptic Warrior Jul 19 '20 at 11:40
  • @ApocalypticWarrior Nice to hear that! If you want you can answer your own question in case someone else will need help in a question similar to yours! – Ric S Jul 19 '20 at 12:40

0 Answers0