def split_data(data, target_name, feature_names, split=[0.75]):
    """
    Split the data into training and testing (and maybe validation) sets.

    Input:
    * data: (dataframe) full dataset
    * target_name (str) name of target column
    * feature_names (list) names of feature columns
    """

    num_rows = len(data)
    # No random sampling because it is a time series.
    ytrain = data[target_name].iloc[: int(num_rows * split[0])]
    Xtrain = data[feature_names].iloc[: int(num_rows * split[0]), :]
    ytest = data[target_name].iloc[int(num_rows * split[-1]):]
    Xtest = data[feature_names].iloc[int(num_rows * split[-1]):, :]

    if len(split) == 2:
        yval = data[target_name].iloc[
            int(num_rows * split[0]): int(num_rows * split[1])
        ]
        Xval = data[feature_names].iloc[
            int(num_rows * split[0]): int(num_rows * split[1]), :
        ]
        return Xtrain, ytrain, Xval, yval, Xtest, ytest
    else:
        return Xtrain, ytrain, Xtest, ytest