Python Multiple criteria Countifs with conditions row by row

Viewed 619

enter image description here

In Excel I have the count with relative (not absolute) reference Historical Wins

= COUNTIFS($D3:$D$13,$D2,$E3:$E$13,1)

How do I loop through all of the rows, and counting the historical occurrences of wins (i.e. Pos = 1) that a particular trainer has in Python (exclude the current result)? Is this possible?

1 Answers

You can get similar results as countifs by doing this. Can you try

df[(df['columname']==D2) & (df['columname']==1)].shape[0]

Here D2 is whatever value you are trying to get the count of in the first column.

Edited based on the comment. This is for multiple values of D2 df.groupby(['D2_column_name']).count() This will give you the count of all values of D2. You can do groupby on multiple columns

Related