1

I have the dataframe

df =A B B A B
    B B B B A
    A A A B B
    A A B A A

And I want to get a vector with the element the appeared the most, per row. So here I will get [B,B,A,A]

What is the best way to do it? In Python2

2 Answers 2

1

Let us using mode

df.T.mode()
   0  1  2  3
0  B  B  A  A
Sign up to request clarification or add additional context in comments.

Comments

0

You can get your vector v with most appearing values with

v = [_[1].value_counts().idxmax() for _ in df.iterrows()].

Be careful when you have multiple elements that occur the most.

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.