def readToDF(path_data='', read_full=True, n_lines=sample_lines): """ Generalized read to df function. PARAMETERS: path_data - string representation of the data file path read_full - boolean value designated if the file is to be read in full or in part n_lines - integer value indicating the number of lines to read from the top of the file RETURN: None - if the file cannot be found df - a pandas DataFrame TODO: extend JSON functionality extend directory reading capability """ if dr.checkPath(path=path_data, is_file=True): df = readFromFile(path_data=path_data, read_full=read_full, n_lines=n_lines) return df else: df = readFromDirectory(path_data=path_data, read_full=read_full, n_lines=n_lines) return df
def readFromDirectory(path_data='', read_full=True, n_lines=sample_lines): df = pd.DataFrame() list_files = dr.listFilesInDir(path_dir=path_data) for f in tqdm(iterable=list_files, desc='Reading files in directory'): path_file = path_data + f if not dr.checkPath(path=path_file, is_file=True): pass else: try: df_temp = readFromFile(path_data=path_file) df = df.append(df_temp) except Exception: pass return df
def selectProject(self, project = ''): """ METHOD SUMMARY METHOD DESCRIPTION PARAMETERS: RETURNS: RESULTS: """ if dr.checkPath(path = self.root+project, is_file = False) and project in self.projects: return project elif project == '': print("No project selected.\nEnter a valid project.") return '' else: print("Error retrieving project.\nCheck the path.") return ''
def loadState(self, path_system_state): """ Function loads a serialized object from a given path. Function tries to find and read a path. PARAMETERS: path_system_state - string representing path to the serialized <SystemState> object RETURNS: Serialized Python2 object RESULTS: None """ #TODO: implement catch for errors if not dr.checkPath(path = path_system_state): with open(path_system_state, 'w+') as f: return cPickle.load(f) with open(path_system_state, 'rb') as f: return cPickle.load(f)
def progressCommand(cmd): cmd = cmd.strip() if cmd == '': return [] elif cmd == 'exit': sys.exit(0) elif cmd == 'help': return helpCommand() elif cmd == 'pwd': return [directory.getPWD().replace('\\', '/')] elif cmd == 'ls': return directory.getList() elif cmd.startswith('cd '): direc = cmd[3:] direc = direc.strip() return directory.changePWD(direc) elif cmd.startswith('move '): cmd = cmd[5:] return directory.move(cmd) elif cmd.startswith('rename '): cmd = cmd[7:] return directory.rename(cmd) elif cmd.startswith('rmf '): cmd = cmd[4:] return directory.removeFile(cmd) elif cmd.startswith('rmdir '): cmd = cmd[6:] return directory.removeDir(cmd) elif cmd.startswith('mkdir '): cmd = cmd[6:] return directory.makeDir(cmd) elif cmd.startswith('mkf '): cmd = cmd[4:] return directory.makeFile(cmd) elif cmd.startswith('get content '): cmd = cmd[12:] return directory.getContent(cmd) elif cmd.startswith('checkpath '): cmd = cmd[10:] return directory.checkPath(cmd) elif cmd.startswith('checkdir '): cmd = cmd[9:] return directory.checkDir(cmd) elif cmd.startswith('checkf '): cmd = cmd[7:] return directory.checkFile(cmd) elif cmd.startswith('zip ls '): cmd = cmd[7:] return directory.zipLS(cmd) elif cmd.startswith('zip getfilesize '): cmd = cmd[16:] return directory.zipGetFileSize(cmd) elif cmd.startswith('zip getcomsize '): cmd = cmd[15:] return directory.zipGetComSize(cmd) elif cmd.startswith('zip '): cmd = cmd[4:] return directory.createZip(cmd) elif cmd.startswith('unzipall '): cmd = cmd[9:] return directory.unzipAll(cmd) elif cmd.startswith('unzip '): cmd = cmd[6:] return directory.unzip(cmd) else: return [ '%r not found.' % (cmd), '7084338aIf you have no idea what to do use "help" command.' ]