def which_percentile(value, d):
    """
    Returns the percentile of 'value' in 'd's distribution.

    :param value: The value whose percentile is required
    :param d: A pandas.Series or Numpy array which represents the distribution
    :return: int
    """
    if len(d) == 0:
        return 0
    return sum(d < value) / len(d)