简体   繁体   English

Python 多个条件 Countifs with conditions row by row

[英]Python Multiple criteria Countifs with conditions row by row

在此处输入图像描述

In Excel I have the count with relative (not absolute) reference Historical Wins在 Excel 我有相对(非绝对)参考历史胜利的计数

= 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 (ie Pos = 1) that a particular trainer has in Python (exclude the current result)?如何循环遍历所有行,并计算特定教练在 Python 中的历史胜利次数(即 Pos = 1)(不包括当前结果)? Is this possible?这可能吗?

You can get similar results as countifs by doing this.通过这样做,您可以获得与countifs相似的结果。 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.这里D2是您试图在第一列中获得计数的任何值。

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.这是针对D2的多个值df.groupby(['D2_column_name']).count()这将为您提供 D2 的所有值的计数。 You can do groupby on multiple columns您可以在多列上进行groupby

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM