Reputation: 1960
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
Upvotes: 1
Views: 35
Reputation: 397
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.
Upvotes: 0