I have a dataframe looks like below:
Name Gender
0 John 0
1 John 1
2 Linda 1
3 Lisa 0
4 Lisa 1
5 Lisa 1
6 Tom 0
7 Tom 1
8 John 0
In this dataframe, name like John is corresponding with two gender value 0 and 1. I want to:
- Count the frequency of names(e.g.John) being 0 and John being 1
- Return a new dataframe of (e.g John) corresponding with the most appeared gender value
- If gender value 0 and 1 has the same val_count, return 1
The returned dataframe should look like below
Name Gender
0 John 0
1 Linda 1
2 Lisa 1
3 Tom 0
Is there a Python Panda code can solve this instead of using for loop?