roy
roy

Reputation: 27

to find the count of how many time a specific number occurred in multiple columns against each row

df = enter image description here

expected output : enter image description here

i want count of number 6 occurred for each row .

so for e.g for x1: number 6 has been repeated for 2 times in column a3 and a6. so the count is 2 for x1.

Upvotes: 0

Views: 21

Answers (1)

Christian Sloper
Christian Sloper

Reputation: 7510

If I understand you correctly, you can do this like this:

(df == 6).sum(axis=1)

Upvotes: 1

Related Questions