def count_number_of_entries(row, feature, ref_counts):
    """Count the number entries for given building based on
    building reference number.

    row : pandas.Series
        EPC dataset row.

    feature: str
        Feature by which to count building entries.
        e.g. "BUILDING_REFERNCE_NUMBER" or "BUILDING_ID"

    ref_counts : pandas.Series
        Value counts for building reference number.

    Return
    ---------
    counts : int
        How many entries are there for given building."""

    building_ref = row[feature]
    try:
        counts = ref_counts[building_ref]
    except KeyError:
        return building_ref

    return counts