mode function

The mode is the most frequent value in an attribute.

For example, the mode in the list [23; 26; 26; 26; 4; 7; 7; 98] is 26.

If the list is made up of numbers which have the same occurrence in the list, the lowest value is considered as mode. (e.g. in the list 2; 2; 2; 2; 1; 1; 1; 1; 100; 1000 the mode is 1, as it has the same occurrence of 2).


Function and parameters

mode(column, group, usemissing)

Parameter

Description

column

It identifies the column to which you want to apply the formula. The column parameter is mandatory.

group

It allows you to group the results by a certain column.

usemissing

A Boolean which indicates whether missing values should be considered or not in the computation of the statistics. The default value, if not otherwise specified, is True.


Example

The following example uses the HR-employee-attrition dataset.

Description

Screenshot

  • In the example here, we want to retrieve the mode of the Job Role attribute. We write the following formula:

  • mode($"JobRole")

  • The mode of the Job Role attribute is Sales Executive.

  • Then ,we want to group our results by the Education Field attribute, and to have a 0 when a value is missing.

  • So the formula is:

  • mode($"JobRole",$"EducationField")

  • The results are as follows:

    • The mode of the Job Role for the Life Sciences education field is Research Scientist.

    • The mode of the Job Role for the Other education fields is Laboratory Technician.