在最大出现次数中使用 DRAW(tie) 检索出现次数最多的元素
Retrieve elements with max occurences with a DRAW(tie) in the max occurrence
例如,我有以下列表
[s, d, s, e, d, d, s]
我需要打印出现次数最多的元素。
示例输出:
2
2
enter image description here
到目前为止,我只能得到一个出现次数最多的元素。请帮我处理最多出现的平局或平局。
你可以这样做:
counts = df[0].value_counts()
counts = counts[counts == counts.max()]
输出:
>>> counts
s 3
d 3
Name: 0, dtype: int64
>>> counts['s']
3
>>> counts['d']
3
例如,我有以下列表 [s, d, s, e, d, d, s]
我需要打印出现次数最多的元素。 示例输出: 2 2
enter image description here
到目前为止,我只能得到一个出现次数最多的元素。请帮我处理最多出现的平局或平局。
你可以这样做:
counts = df[0].value_counts()
counts = counts[counts == counts.max()]
输出:
>>> counts
s 3
d 3
Name: 0, dtype: int64
>>> counts['s']
3
>>> counts['d']
3