def _fold_vmr(ports, i):
    "Reduces movement report to a DataFrame with a single entry for each\n    vessel at the point of it's maximum speed in the channel. Includes a column\n    with the vessel's mean speed.\n    "
    mean = pd.DataFrame(ports[i].groupby(['Name', 'MMSI'])['VSPD kn'].mean()).rename({'VSPD kn': 'Mean Speed kn'}, axis=1).round(1)
    maxes = pd.DataFrame(ports[i].groupby(['Name', 'MMSI'])['VSPD kn'].max()).rename({'VSPD kn': 'Max Speed kn'}, axis=1)
    merged_speeds = maxes.merge(mean, on=['Name', 'MMSI'])
    max_dict = merged_speeds.loc[:, 'Max Speed kn'].to_dict()
    columns = {'Longitude': [], 'Latitude': [], 'Date/Time UTC': [], 'LOA ft': [], 'Course': [], 'AIS Type': [], 'WSPD mph': [], 'GST mph': [], 'WDIR degT': [], 'Buoy Source': [], 'Beam ft': [], 'Heading': [], 'Course Behavior': [], 'Effective Beam ft': [], 'Class': [], 'Location': [], 'Yaw deg': [], 'Transit': [], '% Channel Occupied': []}
    for (key, value) in max_dict.items():
        for k in columns.keys():
            columns[k].append(ports[i][((ports[i].loc[:, 'Name'] == key[0]) & (ports[i].loc[:, 'VSPD kn'] == value))][k].iloc[0])
    for key in columns.keys():
        merged_speeds[key] = columns[key]
    merged_speeds = merged_speeds.reset_index()
    fold_res = merged_speeds
    fold_res.sort_values('Max Speed kn', ascending=False, inplace=True)
    return fold_res
Reduces movement report to a DataFrame with a single entry for each
vessel at the point of it's maximum speed in the channel. Includes a column
with the vessel's mean speed.
def _fold_vmr(ports, i):
    "Reduces movement report to a DataFrame with a single entry for each\n    vessel at the point of it's maximum speed in the channel. Includes a column\n    with the vessel's mean speed.\n    "
    mean = pd.DataFrame(ports[i].groupby(['Name', 'MMSI'])['VSPD kn'].mean()).rename({'VSPD kn': 'Mean Speed kn'}, axis=1).round(1)
    maxes = pd.DataFrame(ports[i].groupby(['Name', 'MMSI'])['VSPD kn'].max()).rename({'VSPD kn': 'Max Speed kn'}, axis=1)
    merged_speeds = maxes.merge(mean, on=['Name', 'MMSI'])
    max_dict = merged_speeds.loc[:, 'Max Speed kn'].to_dict()
    columns = {'Longitude': [], 'Latitude': [], 'Date/Time UTC': [], 'LOA ft': [], 'Course': [], 'AIS Type': [], 'WSPD mph': [], 'GST mph': [], 'WDIR degT': [], 'Buoy Source': [], 'Beam ft': [], 'Heading': [], 'Course Behavior': [], 'Effective Beam ft': [], 'Class': [], 'Location': [], 'Yaw deg': [], 'Transit': [], '% Channel Occupied': []}
    for (key, value) in max_dict.items():
        for k in columns.keys():
            columns[k].append(ports[i][((ports[i].loc[:, 'Name'] == key[0]) & (ports[i].loc[:, 'VSPD kn'] == value))][k].iloc[0])
    for key in columns.keys():
        merged_speeds[key] = columns[key]
    merged_speeds = merged_speeds.reset_index()
    fold_res = merged_speeds
    fold_res.sort_values('Max Speed kn', ascending=False, inplace=True)
    return fold_res