1

I have a pandas data frame with racing results.

   Place BibNum Time 
0   1     2      5:50 
1   2     4      8:09 
2   3     7      10:27 
3   4     3      11:12 
4   5     1      12:13 
... 
34  1     5      2:03 
35  2     9      4:35 
36  3     7      5:36

What I would like to know is how can I get a count of how many times the BibNum showed up where the Place was 1, 2, 3 etc?

I know that I can do a "value_counts" but that is for how many times it shows up in a single column. I also looked into using numpy "where" but that is using a conditional like greater than or less than.

1
  • If you want a matrix: pd.crosstab(df['Place'], df['BibNum']), else df[['Place', 'BibNum']].value_counts() Commented Jan 11, 2023 at 5:27

1 Answer 1

1

IIUC , this is what you need:

out = df.groupby(['Place','BibNum']).size()
Sign up to request clarification or add additional context in comments.

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.