def station_locations(df, id_index):
    """
    Creates a dictionary with station IDs as keys and locations as values.

    Parameters
    ----------
    df : pandas DataFrame
        Bikeshare trip data.
    id_index : dict
        Maps station ID (arbitrary integer) to the range from 0 to number of stations

    Returns
    -------
    locations : dict
        key : station index (returned from id_index)
        value : tuple (longitude, latitude)

    """

    # Create Dictionary Station : Position
    locations = dict()

    for e in id_index.keys():

        if df[df['start_stat_id'] == e]['start_stat_lat'].shape[0]:
            locations[id_index[e]] = (df[df['start_stat_id'] == e]['start_stat_long'].iloc[0],
                                      df[df['start_stat_id'] == e]['start_stat_lat'].iloc[0])
        else:
            locations[id_index[e]] = (df[df['end_stat_id'] == e]['end_stat_long'].iloc[0],
                                      df[df['end_stat_id'] == e]['end_stat_lat'].iloc[0])

    return locations