def get_data_by_state(path, dates, state, column):
    """Reads a ProCoDA file and extracts the time and data column for each
    iteration ofthe given state.

    Note: column 0 is time, the first data column is column 1.

    :param path: The path to the folder containing the ProCoDA data file(s), defaults to the current directory
    :type path: string
    :param dates: A single date or list of dates for which data was recorded, formatted "M-D-YYYY"
    :type dates: string or string list
    :param state: The state ID number for which data should be plotted
    :type state: int
    :param column: The integer index of the column that you want to extract OR the header of the column that you want to extract
    :type column: int or string

    :return: A list of lists of the time and data columns extracted for each iteration of the state. For example, if "data" is the output, data[i][:,0] gives the time column and data[i][:,1] gives the data column for the ith iteration of the given state and column. data[i][0] would give the first [time, data] pair.
    :type: list of lists of lists

    :Examples:

    .. code-block:: python

        data = get_data_by_state(path='/Users/.../ProCoDA Data/', dates=["6-19-2013", "6-20-2013"], state=1, column=28)
    """
    data_agg = []
    day = 0
    first_day = True
    overnight = False
    extension = ".xls"
    if path[-1] != '/':
        path += '/'

    if not isinstance(dates, list):
        dates = [dates]

    for d in dates:
        state_file = path + "statelog " + d + extension
        data_file = path + "datalog " + d + extension

        states = pd.read_csv(state_file, delimiter='\t')
        data = pd.read_csv(data_file, delimiter='\t')

        states = np.array(states)
        data = np.array(data)

        # get the start and end times for the state
        state_start_idx = states[:, 1] == state
        state_start = states[state_start_idx, 0]
        state_end_idx = np.append([False], state_start_idx[0:-1])
        state_end = states[state_end_idx, 0]

        if overnight:
            state_start = np.insert(state_start, 0, 0)
            state_end = np.insert(state_end, 0, states[0, 0])

        if state_start_idx[-1]:
            np.append(state_end, data[0, -1])

        # get the corresponding indices in the data array
        data_start = []
        data_end = []
        for i in range(np.size(state_start)):
            add_start = True
            for j in range(np.size(data[:, 0])):
                if (data[j, 0] > state_start[i]) and add_start:
                    data_start.append(j)
                    add_start = False
                if data[j, 0] > state_end[i]:
                    data_end.append(j-1)
                    break

        if first_day:
            start_time = data[0, 0]

        # extract data at those times
        for i in range(np.size(data_start)):
            t = data[data_start[i]:data_end[i], 0] + day - start_time
            if isinstance(column, int):
                c = data[data_start[i]:data_end[i], column]
            else:
                c = data[column][data_start[i]:data_end[i]]
            if overnight and i == 0:
                data_agg = np.insert(data_agg[-1], np.size(data_agg[-1][:, 0]),
                                     np.vstack((t, c)).T)
            else:
                data_agg.append(np.vstack((t, c)).T)

        day += 1
        if first_day:
            first_day = False
        if state_start_idx[-1]:
            overnight = True

    return data_agg
Reads a ProCoDA file and extracts the time and data column for each
    iteration ofthe given state.

    Note: column 0 is time, the first data column is column 1.

    :param path: The path to the folder containing the ProCoDA data file(s), defaults to the current directory
    :type path: string
    :param dates: A single date or list of dates for which data was recorded, formatted "M-D-YYYY"
    :type dates: string or string list
    :param state: The state ID number for which data should be plotted
    :type state: int
    :param column: The integer index of the column that you want to extract OR the header of the column that you want to extract
    :type column: int or string

    :return: A list of lists of the time and data columns extracted for each iteration of the state. For example, if "data" is the output, data[i][:,0] gives the time column and data[i][:,1] gives the data column for the ith iteration of the given state and column. data[i][0] would give the first [time, data] pair.
    :type: list of lists of lists

    :Examples:

    .. code-block:: python

        data = get_data_by_state(path='/Users/.../ProCoDA Data/', dates=["6-19-2013", "6-20-2013"], state=1, column=28)