pythonpandasdataframepandas-groupbyoversampling

Create row of most frequent value in each dataframe column


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   

Solution

  • Check with mode

    df.mode()
      Gender   Eyes    Hair Height
    0      M  Brown  Blonde   <6ft