Ejemplo n.º 1
0
def rand_param(parameters):
    """
    Obtains the parameters for the random dataset generator.
    :param parameters: The parameters for the creation (number of rows, numbers of columns,...).
    :return: A tuple of the parameters.
    """
    num_rows, num_col, values = 0, 0, []
    if parameters["columns"]:
        num_col = int(parameters["columns"])
    else:
        print('How many columns?')
        al.voice('How many columns?')
        query = al.query_input()
        while not query.isnumeric():
            print(
                'Incorrect input.\nIt is not a number.\nPlease introduce one.')
            al.voice(
                'Incorrect input.\nIt is not a number.\nPlease introduce one.')
            query = al.query_input()
        num_col = int(query)

    if parameters["rows"]:
        num_rows = int(parameters["rows"])
    else:
        print('How many rows?')
        al.voice('How many rows?')
        query = al.query_input()
        while not query.isnumeric():
            print(
                'Incorrect input.\nIt is not a number.\nPlease introduce one.')
            al.voice(
                'Incorrect input.\nIt is not a number.\nPlease introduce one.')
            query = al.query_input()
        num_rows = int(query)

    if parameters["values"]:
        values = parameters["values"]
    else:
        print('What is the minimum value?')
        al.voice('What is the minimum value?')
        query = al.query_input()
        while not al.isnumber(query):
            print(
                'Incorrect input.\nIt is not a number.\nPlease introduce one:')
            al.voice(
                'Incorrect input.\nIt is not a number.\nPlease introduce one.')
            query = al.query_input()
        values.append(float(query))
        print('And the maximum?')
        al.voice('And the maximum?')
        query = al.query_input()
        while not al.isnumber(query):
            print(
                'Incorrect input.\nIt is not a number.\nPlease introduce one:')
            al.voice(
                'Incorrect input.\nIt is not a number.\nPlease introduce one.')
            query = al.query_input()
        values.append(float(query))

    return num_rows, num_col, values
Ejemplo n.º 2
0
def get_subdataset_rows(parameters):
    """
    Obtains a subset of the dataset by its rows.
    :param parameters: The parameter of the function(dataset name,...).
    """
    workspace = al.Workspace()
    data_name = parameters['Dataset']
    dataset = workspace.get_dataset(data_name)

    if parameters["from"]:
        index_a = int(parameters["from"])
    else:
        print('From what row number?')
        al.voice('From what row number?')
        query = al.query_input()
        while not al.isnumber(query):
            print(
                'Incorrect input.\nIt is not a number.\nPlease introduce one:')
            al.voice(
                'Incorrect input.\nIt is not a number.\nPlease introduce one.')
            query = al.query_input()
        index_a = int(query)
    if parameters["to"]:
        index_b = int(parameters['to'])
    else:
        print('To what row number?')
        al.voice('To what row number?')
        query = al.query_input()
        while not al.isnumber(query):
            print(
                'Incorrect input.\nIt is not a number.\nPlease introduce one:')
            al.voice(
                'Incorrect input.\nIt is not a number.\nPlease introduce one.')
            query = al.query_input()
        index_b = int(query)

    if index_b < index_a:
        print(
            'This operation cannot be done.\nThe starting row number is greater than the last row number.'
        )
        raise Exception()

    dataset = dataset.iloc[index_a:index_b]
    num = workspace.get_counter('sub')
    name = 'subrow' + str(num) + data_name
    workspace.save_dataset(name, dataset)
    txt = 'The sub-dataset by the rows is saved as ' + name
    print(txt)
Ejemplo n.º 3
0
def split_by_rows(parameters):
    """
    Split a dataset into n datasets of m rows.
    :param parameters: The parameters of the function (dataset name, size of the split dataset for the rows).
    """
    workspace = al.Workspace()
    name_data = parameters['Dataset']
    dataset = workspace.get_dataset(name_data)

    if parameters['split']:
        div = int(parameters['split'])
    else:
        print('How many rows will each dataset have?')

        query = al.query_input()
        while not al.isnumber(query):
            print(
                'Incorrect input.\nIt is not a number.\nPlease introduce one:')

            query = al.query_input()
        div = int(query)

    it = 0
    names = []
    while it < dataset.index.size:
        div_dataset = dataset.iloc[it:it + div]
        num = workspace.get_counter('split')
        name = name_data + 'r' + str(num)
        names.append(name)
        workspace.save_dataset(name, div_dataset)
        it = it + div

    print('The splits of ' + name_data + ' are saved as: ' + str(names)[1:-1])