2

I've a df with this make-up. I'm interested in counting strings in the columns that have numerical names i.e. ['1','2','3','4','5']

enter image description here

And would return a series something like:

string1 10
strinsag1 5
strins1 5

...

I've tried various methods of groupby, Counter, and stack but I haven't found a solution that works

1 Answer 1

3

You can stack the data and use value_counts():

df[['1','2','3','4','5']].stack().value_counts()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.