ColumnMode
Gets the mode value of one or more columns. Furthermore, can get the mode while being grouped by another column or category, perform a rolling mode or sliding window mode, can get the mode for only rows that meet a condition, and can add the result to the dataframe as a new column
Options
columns: Specifies columns to calculate mode values
where: Specifies a condition for the calculation
group: Groups the data before performing the operation
rolling: Specifies the rolling window overwhich to perform the calculation
addToDataframe: Indicates whether to add the result to the dataframe
Examples
Example 1 - Get Mode of a Single Column
The mode is the most frequently occurring value in a column. In this example, we calculate the mode of the Cloud3pm column to find the most common cloud cover value in the afternoon across the dataset.
#> ColumnMode Cloud3pm --print
AFLEFT
weatherDfMode = weatherDf['Cloud3pm'].mode()
print(weatherDfMode) #)2 AFRIGHT
Example 2 - Get Mode of Multiple Columns
When we want to understand the most common values across several columns at once, we can calculate the mode for each column in a single call. In this case, we compute the mode for Humidity3pm, Humidity9am, and Temp3pm.
#> ColumnMode Humidity3pm Humidity9am Temp3pm --print
AFLEFT
weatherDfMode = weatherDf [ [Humidity3pm, Humidity9am, 'Temp3pm'] ].mode()
print(weatherDfMode) #)4 AFRIGHT