def aggregate_sart(data, sub_num):
    """
    Aggregate data from the SART task.

    Calculates various summary statistics for the SART task for a given subject.

    Parameters
    ----------
    data : dataframe
        Pandas dataframe containing a single subjects trial data for the task.
    sub_num : str
        Subject number to which the data file belongs.

    Returns
    -------
    stats : list
        List containing the calculated data for the subject.
    """
    follow_error_rt = data.loc[data.accuracy.shift() == 0, 'RT'].mean()
    follow_correct_rt = data.loc[data.accuracy.shift() == 1, 'RT'].mean()
    total_rt = data['RT'].mean()
    total_rtsd = data['RT'].std()
    total_rtcov = total_rtsd / total_rt
    frequent_rt = data[data['stimulus'] != 3]['RT'].mean()
    frequent_rtsd = data[data['stimulus'] != 3]['RT'].std()
    frequent_rtcov = frequent_rtsd / frequent_rt
    infrequent_rt = data[data['stimulus'] == 3]['RT'].mean()
    infrequent_rtsd = data[data['stimulus'] == 3]['RT'].std()
    infrequent_rtcov = infrequent_rtsd / infrequent_rt
    sart_error_count = data[data['stimulus'] == 3]['key press'].sum()
    sart_errors_num_items = data[data['stimulus'] == 3].shape[0]
    sart_errors_prop = sart_error_count / sart_errors_num_items
    return [sub_num, follow_error_rt, follow_correct_rt, total_rt,
        total_rtsd, total_rtcov, frequent_rt, frequent_rtsd, frequent_rtcov,
        infrequent_rt, infrequent_rtsd, infrequent_rtcov, sart_error_count,
        sart_errors_prop, sart_errors_num_items]
