def _cut_series_by_quantile(df, ts_settings, quantile=0.95, top=True):
    """
    Select top-n or bottom-n series by quantile
    
    df: pandas df
    ts_settings: dict
        Parameters for datetime DR projects
    quantile: np.float
        threshold for series to select
    top: bool
        Select highest (True) or lowest series (False)
    
    Returns:
    --------
    pandas df
    """
    
    
    series_id = ts_settings['series_id']
    target = ts_settings['target']

    df_agg = df.groupby(series_id).mean()

    if top:
        selected_series_names = df_agg[
            df_agg[target] >= df_agg[target].quantile(quantile)
        ].index.values
    else:
        selected_series_names = df_agg[
            df_agg[target] <= df_agg[target].quantile(quantile)
        ].index.values

    return selected_series_names