import math


def calc_entropy(data, base=2):
    """
    Calculate the entropy of data. Using documentation from
    scipy.stats.entropy as the basis for this code
    (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html).
    :param data: Measure the entropy of this object
    :return: Calculated entropy value
    """
    if not data:
        return 0

    # calculate frequency list
    chars = set(data)
    frequencies =  [float(data.count(ch)) / len(data) for ch in chars]

    # calculate shannon entropy
    H = -sum([freq  * math.log(freq) / math.log(base) for freq in frequencies ])
    return H