def optimize_graph(edges, aggr_type, fr='from_int', to='to_int', weight_col
    ='weight'):
    """
    Optimize the graph in terms of keeping only e.g. 'min' or 'max' (fastest / slowest) edges between nodes.
    This process can dramatically decrease the size of the graph.

    Parameters
    ----------

    edges : pd.DataFrame
        Pandas DataFrame containing the edge information.
    aggr_type : str
        Aggregation type. Possible values are: 'min', 'max', 'mean', 'median'

    """
    optimized = edges.groupby([fr, to])[weight_col].agg(aggr_type).reset_index(
        ).merge(edges, on=[fr, to]).rename(columns={(weight_col + '_x'):
        weight_col}).drop_duplicates([fr, to]).drop(weight_col + '_y', axis=1)
    return optimized
