def load_from_tsfile_to_dataframe(full_file_path_and_name, replace_missing_vals_with='NaN'):
    data_started = False
    instance_list = []
    class_val_list = []
    has_time_stamps = False
    has_class_labels = False
    uses_tuples = False
    is_first_case = True
    with open(full_file_path_and_name, 'r') as f:
        for line in f:
            if line.strip():
                if ('@timestamps' in line.lower()):
                    if ('true' in line.lower()):
                        has_time_stamps = True
                        raise Exception('Not suppoorted yet')
                    elif ('false' in line.lower()):
                        has_time_stamps = False
                    else:
                        raise Exception('invalid timestamp argument')
                if ('@classlabel' in line.lower()):
                    if ('true' in line):
                        has_class_labels = True
                    elif ('false' in line):
                        has_class_labels = False
                    else:
                        raise Exception('invalid classLabel argument')
                if ('@data' in line.lower()):
                    data_started = True
                    continue
                if data_started:
                    line = line.replace('?', replace_missing_vals_with)
                    dimensions = line.split(':')
                    if is_first_case:
                        num_dimensions = len(dimensions)
                        if has_class_labels:
                            num_dimensions -= 1
                        is_first_case = False
                        for dim in range(0, num_dimensions):
                            instance_list.append([])
                        if dimensions[0].startswith('('):
                            uses_tuples = True
                    this_num_dimensions = len(dimensions)
                    if has_class_labels:
                        this_num_dimensions -= 1
                    if (this_num_dimensions != num_dimensions):
                        raise Exception('inconsistent number of dimensions')
                    for dim in range(0, num_dimensions):
                        if uses_tuples:
                            without_brackets = dimensions[dim].replace('(', '').replace(')', '').split(',')
                            without_brackets = [float(i) for i in without_brackets]
                            indices = []
                            data = []
                            i = 0
                            while (i < len(without_brackets)):
                                indices.append(int(without_brackets[i]))
                                data.append(without_brackets[(i + 1)])
                                i += 2
                            instance_list[dim].append(pd.Series(data, indices))
                        else:
                            data_series = dimensions[dim].split(',')
                            data_series = [float(i) for i in data_series]
                            instance_list[dim].append(pd.Series(data_series))
                    if has_class_labels:
                        class_val_list.append(dimensions[num_dimensions].strip())
    x_data = pd.DataFrame(dtype=np.float32)
    for dim in range(0, num_dimensions):
        x_data[('dim_' + str(dim))] = instance_list[dim]
    if has_class_labels:
        return (x_data, np.asarray(class_val_list))
    return x_data
def load_from_tsfile_to_dataframe(full_file_path_and_name, replace_missing_vals_with='NaN'):
    data_started = False
    instance_list = []
    class_val_list = []
    has_time_stamps = False
    has_class_labels = False
    uses_tuples = False
    is_first_case = True
    with open(full_file_path_and_name, 'r') as f:
        for line in f:
            if line.strip():
                if ('@timestamps' in line.lower()):
                    if ('true' in line.lower()):
                        has_time_stamps = True
                        raise Exception('Not suppoorted yet')
                    elif ('false' in line.lower()):
                        has_time_stamps = False
                    else:
                        raise Exception('invalid timestamp argument')
                if ('@classlabel' in line.lower()):
                    if ('true' in line):
                        has_class_labels = True
                    elif ('false' in line):
                        has_class_labels = False
                    else:
                        raise Exception('invalid classLabel argument')
                if ('@data' in line.lower()):
                    data_started = True
                    continue
                if data_started:
                    line = line.replace('?', replace_missing_vals_with)
                    dimensions = line.split(':')
                    if is_first_case:
                        num_dimensions = len(dimensions)
                        if has_class_labels:
                            num_dimensions -= 1
                        is_first_case = False
                        for dim in range(0, num_dimensions):
                            instance_list.append([])
                        if dimensions[0].startswith('('):
                            uses_tuples = True
                    this_num_dimensions = len(dimensions)
                    if has_class_labels:
                        this_num_dimensions -= 1
                    if (this_num_dimensions != num_dimensions):
                        raise Exception('inconsistent number of dimensions')
                    for dim in range(0, num_dimensions):
                        if uses_tuples:
                            without_brackets = dimensions[dim].replace('(', ).replace(')', ).split(',')
                            without_brackets = [float(i) for i in without_brackets]
                            indices = []
                            data = []
                            i = 0
                            while (i < len(without_brackets)):
                                indices.append(int(without_brackets[i]))
                                data.append(without_brackets[(i + 1)])
                                i += 2
                            instance_list[dim].append(pd.Series(data, indices))
                        else:
                            data_series = dimensions[dim].split(',')
                            data_series = [float(i) for i in data_series]
                            instance_list[dim].append(pd.Series(data_series))
                    if has_class_labels:
                        class_val_list.append(dimensions[num_dimensions].strip())
    x_data = pd.DataFrame(dtype=np.float32)
    for dim in range(0, num_dimensions):
        x_data[('dim_' + str(dim))] = instance_list[dim]
    if has_class_labels:
        return (x_data, np.asarray(class_val_list))
    return x_data