def calculate_cycle_values(data, direction_label, cycle_label, initial_cycle):
    """The cycle every data row belongs to is calculated from the direction
    column and added as a new data column.
    The cycle count starts at the value provided in initial_cycle.

    INPUT:
        data: DataFrame.

        direction_label: string, label of the direction column in data.

        cycle_label: string, label for the new cycle column.

        initial_cycle: integer.
    """
    class Tracker:
        """This class acts as a data container for the assign_cycle function,
        since it's needed to keep track of some variables out of its scope.
        """
        cycle = initial_cycle
        initial_sign = data.get_value(0, direction_label)
        former_sign = -initial_sign

    def assign_cycle(sign):
        """Gives a cycle value to the sign provided, relative to the initial
        sign on the data and the sign assigned just before.

        INPUT:
            sign: integer with values 1 or -1.

        OUTPUT:
            integer.
        """
        if Tracker.initial_sign == sign and Tracker.former_sign != sign:
            Tracker.cycle += 1

        Tracker.former_sign = sign
        return Tracker.cycle

    data[cycle_label] = data.loc[:, direction_label].apply(assign_cycle)