KitDocumentation

ColumnAverage

Gets the average value of one or more columns. Furthermore, can get the average while being grouped by another column or category, perform a rolling average or sliding window average, can get an average 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 aberage values
where: Specifies a condition for the calculation
rolling: Specifies the rolling window overwhich to perform the calculation
group: Groups the data before performing the operation
addToDataframe: Indicates whether to add the result to the dataframe

Examples

Example 1 - Get Average of a Single Column

It is common to want to see the average value of a column to get a feel of the values in the column. Here, we have a weather dataset and we get the average value of the MaxTemp column.
#> ColumnAverage MaxTemp --print
AFLEFT 
weatherDfMean = weatherDf['MaxTemp'].mean()
print(weatherDfMean) #)2 AFRIGHT

Example 2 - Get Average of Multiple Columns

Rather than getting the average of a single columns, we can get the average of multiple columns simplify by stating multiple columns.
#> ColumnAverage WindGustSpeed MinTemp Evaporation --print
AFLEFT 
weatherDfMean = weatherDf [ ['WindGustSpeed', 'MinTemp', 'Evaporation'] ].mean()
print(weatherDfMean) #)4 AFRIGHT

Example 3 - Get Rolling Average and Add to Dataframe

With sorted data according to an index or time, it is common to want to know an average over only the X most recent records. We get the column average over a rolling window of the last 5 rows. Additionally, we add the result back to the dataframe to align the windowed averages with the rows in which they occur.
#> ColumnAverage --columns Sunshine --rolling 5 --addToDataframe
AFLEFT 
weatherDfMeanRolling5 = weatherDf['Sunshine'].rolling(window=5, min_periods=1).mean()
weatherDf['SunshineMeanRolling5'] = pd.Series()
weatherDf['SunshineMeanRolling5'] = weatherDfMeanRolling5 AFRIGHT