def average_top_runs(speed_df,rank_column,weapon_column='Weapon',time_column='Time (s)',top_pos=1):
    """
    Returns a DataFrame with the average top speedrun times for each weapon class,
    as ordered by the 'rank_column' column.
    This will take the 'top_pos' times into the average. For top_pos=1, that's
    only the fastest time, top_pos=2 means it's the fastest 2 times, etc.
    Return value is ordered by time_column, going from fastest to slowest.
    """

    #Pick out the top runs
    avg = speed_df[speed_df[rank_column]<=top_pos]

    #Group by weapon type and get the mean values
    avg = avg.groupby(weapon_column).mean().reset_index()

    #Simplify time values
    avg['Time (s)'] = avg['Time (s)'].apply(lambda x: round(x,2))

    #Sort weapons
    avg = avg.sort_values('Time (s)',ascending=True)

    #Update index to correspond to rankings (ie start at 1 rather than 0)
    avg = avg.reset_index()
    avg.index += 1

    #Return
    return avg