import math


def _get_occurence(df, do_reverse = False):
    """
    _get_occurence finds and returns the first/ last date for which a value was recorded in a dataframe.

    :param df: the dataframe to look through.
    :param do_reverse: specifies, whether to look for the first/ last occurence.
    :return: the year of the first/ last occurence.
    """

    if do_reverse:
        df = df[df.columns[::-1]]

    for col in df:
        val = df[col].values[0]
        try:
            float(val)
            if not math.isnan(float(val)):
                return df[col].name
        except ValueError:
            continue