-1

CONTEXT

I want to create a top row with the most frequent values of each column.

CURRENT CODE

df = df.loc[df['Gender'] == 'M']
df = df('Gender').count()

DATA SAMPLE

Gender      Eyes      Hair    Height
  M         Brown     Brown    >6ft
  M         Blue      Blonde   <6ft
  M         Brown     Blonde   <6ft

EXPECTED OUTCOME

Gender      Eyes      Hair    Height
  M         Brown     Blonde    <6ft   
KL_
  • 293
  • 6
  • 22

2 Answers2

2

It's exactly what the mode function in Pandas does. Assuming your data sample is df, you can obtain your expected output using the following line of code

df.mode()
Kavish
  • 69
  • 6
1

Check with mode

df.mode()
  Gender   Eyes    Hair Height
0      M  Brown  Blonde   <6ft
BENY
  • 317,841
  • 20
  • 164
  • 234