找出特定数字在多行中相对于每一行发生了多少次计数

问题描述 投票:0回答:1

df = enter image description here

预期输出:enter image description here

我希望每行发生6号计数。

例如对于x1:数字6已在列a3和a6中重复了2次。因此x1的计数为2。

python group-by count pandas-groupby
1个回答
1
投票

如果我对您的理解正确,您可以这样做:

(df == 6).sum(axis=1)
© www.soinside.com 2019 - 2024. All rights reserved.