def find_nearest_index(data, value):
    """Find the index of the entry in data that is closest to value.

    Example:
    >>> data = [0, 3, 5, -2]
    >>> i = partmc.find_nearest_index(data, 3.4)
    returns i = 1

    """
    min_diff = abs(value - data[0])
    min_i = 0
    for i in range(1,len(data)):
        diff = abs(value - data[i])
        if diff < min_diff:
            min_diff = diff
            min_i = i
    return min_i