pandas_extension.ResultFrameAggregator

pandas_extension.ResultFrameAggregator(
    self,
    agg=None,
    override_name=None,
    **kwargs,
)

Aggregates a MIKE IO 1D result DataFrame with hierarchical columns along specific levels.

Levels are categorized as entity levels, quantity levels, and aggregation levels. Aggregation is only performed along aggregation levels. Quantity levels define the resulting DataFrame’s columns. Entity levels define the resulting DataFrame’s indices.

Parameters

Name Type Description Default
agg str or callable Default aggregation function to be applied along DataFrame column levels. Any str or callable accepted by pd.DataFrame.agg may be used. Example: - “max” : Take the maximum value. - “min” : Take the minimum value. - np.mean: Take the mean value. If not specified, then the ‘time’ parameter must be provided and is used as default. None
override_name str Set a custom name for the overall aggregation. By default uses the agg function name. None
**kwargs Aggregation functions for specific DataFrame column levels (e.g. time=‘min’, chainage=‘mean’) {}

Attributes

Name Type Description
entity_levels list of str The DataFrame column levels used to uniquely identify an entity. (e.g. [‘group’,‘name’,‘tag’]).
quantity_levels list or str The DataFrame column levels used to uniquely identify a quantity (e.g. [‘quantity’,‘derived’]).
agg_levels list of str The DataFrame column levels that will be aggregated along, in order. (e.g. [‘duplicate’,‘chainage’,‘time’]).
agg_functions dict of str: callable A dictionary with keys matching agg_levels, and values being the aggregation functions.

Examples

See which levels will be aggregated, and in what order.

>>> agg = ResultFrameAggregator('max')
>>> agg.agg_levels
['duplicate', 'chainage', 'time']

Aggregate along duplicate, chainage, and time, taking the max of each quantity

>>> agg = ResultFrameAggregator('max')
>>> agg.aggregate(df)

Always take the first chainage value, but take the max of all other levels.

>>> agg = ResultFrameAggregator('max', chainage='first')
>>> agg.aggregate(df)

Same result as above, but with explicit argument names.

>>> agg = ResultFrameAggregator(duplicate='max', time='max', chainage='first')
>>> agg.aggregate(df)

Same as above, but recognizing that time=‘max’ becomes the default for unspecifed levels.

>>> agg = ResultFrameAggregator(chainage='first' time='max')
>>> agg.aggregate(df)

Methods

Name Description
aggregate Aggregate along the duplicate, chainage, and time dimensions.
get_agg_function Get the aggregation function for a level.
set_agg_function Set the aggregation function for a level.

aggregate

pandas_extension.ResultFrameAggregator.aggregate(df)

Aggregate along the duplicate, chainage, and time dimensions.

get_agg_function

pandas_extension.ResultFrameAggregator.get_agg_function(level_name)

Get the aggregation function for a level.

Parameters

Name Type Description Default
level_name str The level name to aggregate along. Must be one of the agg_levels. required

Returns

Name Type Description
agg pd.DataFrame.agg func-like The aggregation function.

set_agg_function

pandas_extension.ResultFrameAggregator.set_agg_function(level_name, agg)

Set the aggregation function for a level.

Parameters

Name Type Description Default
level_name str The level name to aggregate along. Must be one of the agg_levels. required
agg pd.DataFrame.agg func-like The aggregation function. required