How can I count number of non-null columns in a row

Options
Nikhil
Nikhil Registered Posts: 1 ✭✭✭

Hi,

How can I count number of non-null columns in a row.

Similar to CountA[D1:D5] in excel.

Thanks in advance

Answers

  • djoguns
    djoguns Registered Posts: 11 ✭✭✭✭
    Options

    Hi Nikhil,

    See below:

    df as your dataframe.

    df.apply(lambda x: x.count(), axis=1)

    Or better still assign the count to another variable.

    df['non_null_count'] = df.apply(lambda x: x.count(), axis=1)

    Cheers.

Setup Info
    Tags
      Help me…