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])
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
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)
def get_subdataset_columns(parameters): """ Obtains a subset of the dataset by its columns. :param parameters: The parameter of the function(dataset name,...). """ workspace = al.Workspace() data_name = parameters['Dataset'] dataset = workspace.get_dataset(data_name) cols = [] if parameters["cols"]: cols = parameters['cols'] else: stop = False while not stop: cols.append(al.obtain_column(dataset)) print('Do you want to continue? yes or no?') response = al.query_input() if response == 'no': stop = True dataset = dataset[cols] num = workspace.get_counter('sub') name = 'subcol' + str(num) + data_name workspace.save_dataset(name, dataset) txt = 'The sub-dataset by the rows is saved as ' + name print(txt)
def get_int_number(parameters): """ Obtains or asks for a integer number. :param parameters: the parameters of the function(number,...). :return: An integer number. """ if parameters["number"]: num_points = int(parameters["number"]) else: print('How many point do you want to reduce it?') al.voice('How many point do you want to reduce it?') 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_points = int(query) return num_points
def get_epsilon(parameters): """ Obtains or asks for the epsilon. :param parameters: the parameters of the function(number,...). :return: The epsilon value. """ # Although we are asking for the epsilon, the value it is saved in the key number if parameters["number"]: num_points = parameters["number"] else: print('What is the value of epsilon?') al.voice('What is the value of epsilon?') 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_points = float(query) return num_points
def ask_for_dataset_extension(files): """ Ask for the dataset extension file. :param files: All files with the same name. :return: The extension file. """ print('What is the file extension (txt, csv)?') print('All the files that has been found with the same name: ' + str(files)) return al.query_input()
def change_name(parameters): """ Change the name of an existing dataset. :param parameters: The parameter of the function (dataset name,...). """ workspace = al.Workspace() or_name = parameters['Dataset'] into_name = parameters['NameInto'] if not into_name: print('Into what name do you want to change ' + or_name + '?') into_name = al.query_input() while into_name in workspace.get_all_dataset(): print('There is already a dataset with the name ' + into_name + '.\nPlease write another name.') into_name = al.query_input() data = workspace.get_value(or_name) workspace.remove_dataset(or_name) workspace.save_dataset(into_name, data) print('The dataset named ' + or_name + ' has been updated into ' + into_name)
def ask_for_dataset_path(): """ Ask for the dataset path. :return: The path introduced. """ print('Where is it located?') print('Current path is ' + os.getcwd()) query = al.query_input() if query == 'here': path = os.getcwd() else: path = query return path