You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
5.4 KiB

3 years ago
  1. # Data Science Workflow
  2. ## Introduction ##
  3. Data science is mainly the work that a graduated student has to do along his master. This post explores through examples how to use the command line in an efficient and productive way for data science tasks. In this sense, data science workflow consists on to (*i*)obtain, (*ii*)scrub, (*iii*)explore, (*iv*)model, and (*v*)**report your data**.
  4. To develop each of stage we are going to explore different tools and supporting lectures. However, the main idea is to create a *highly reproducible environment*. This means, that any person(student) can follow your procedure to obtain the same results.
  5. Then, to create a reproducible workflow (environment), let's start by the main base of our work system, the Operative System (OS).
  6. Therefore, the most basic and reproducible OSs are Unix like OS; similar to Linux or Macos OSs. This kind of OS, use a main user's interface to input and output data; the interface is called *Command Line*.
  7. ---
  8. The Unix philosophy
  9. According with [^1], Unix philosophy is an established cultural norm or a reference manual software developers need to adhere to whenever they create software for Unix-like systems. Its emphasis on the software structure is simplicity, modularity, and extensive maintenance. The most important point is that *The programs you write should implement a universal interface like handling text streams.*
  10. ---
  11. ## Command-line basics ##
  12. This new way(philosophy) to work requires an overall understanding about we should call the command line, and according to [^2] it is mainly defined by:*(a)the command-line tools, (b)the terminal, (c)the shell, and (d)the operating system*.
  13. ### Command-line tools ###
  14. We use them by typing their corresponding commands on the *terminal*. There are different types of command-line tools, examples of this tools are: `ls`, `cat`, and `more` commands.
  15. ### Terminal ###
  16. The terminal is the application where we type our commands in; see next figure:
  17. ![Terminal](https://i.blogs.es/56c9ee/cd/450_1000.jpg "terminal-ubuntu")
  18. The dollar sign `$` shown in the figure is known as the *prompt*, and you are watching the typical *Ubuntu terminal* in version 18.04; other kind of prompts are `>`, `~`, `->`, among others.
  19. The *terminal* is some kind of front-end to observe the input/output of a command process task.
  20. ### Shell ###
  21. The third element is the *shell*. Once we have typed *a command-line tool* and pressed `<Enter>`, the terminal sends that command to the *shell*. The shell is a program that interprets the command. The image shows the Bash (Bourne Again Shell), but there are many others available like *Z shell*.
  22. ### Operating system ###
  23. The last element is the operating system (OS), which is *GNU/Linux* in a Docker image or Virtual Machine. Linux is the name of the kernel, which is the heart of the operating system. The kernel has a direct contact with the CPU, disks, and other hardware. The kernel also executes the *command-line tools*. GNU, which stands for GNU’s not UNIX, refers to the set of basic tools.
  24. ## Type of command-line tools ##
  25. The *command-line* tools are some kind of apps called by text and return text, strings or files. Each command-line tool can be one of the following five types according to [^2]:
  26. * A binary executable
  27. * A shell builtin
  28. * An interpreted script
  29. * A shell function
  30. * An alias
  31. The most common are the first two, while the others allow to build up a toolbox that will make us more efficient and productive.
  32. ### Binary executable ###
  33. Binary executables are programs in the classical sense. A binary executable is created by compiling source code to machine code. This means that when you open the file in a text editor you cannot read it, most probably you will see strange characters.
  34. ### Shell builtin ###
  35. *Shell builtins* are command-line tools provided by the shell, which is Bash in our case. Examples include `cd` and `help`. These cannot be changed. Shell builtins may differ between shells. Like binary executables, they cannot be easily inspected or changed.
  36. ### Interpreted Script ###
  37. An interpreted script is a text file that is executed by a binary executable. Examples include: *Python*, *R*, and *Bash scripts*. One great advantage of an interpreted script is that you can read and change it. E.g. a script `fac.py`. This script is interpreted by Python not because of the file extension .py, but because the first line of the script defines the binary that should execute it.
  38. # Testing some tools #
  39. We employ the term command-line tool a lot, but so far, we have not yet explained what we actually mean by it. We use it as an umbrella term for anything that can be executed from the command line. Thus, lets try something:
  40. go to your working folder by using `cd` command
  41. ```bash
  42. $ cd /my/working/folder/
  43. ```
  44. then let's change the prompt:
  45. ```bash
  46. $ export PS1='> '
  47. ```
  48. let's update our system:
  49. ```bash
  50. > sudo apt update
  51. Pass:
  52. > sudo apt upgrade
  53. ```
  54. then, install some useful packages:
  55. ```bash
  56. > sudo apt install pandoc
  57. > sudo apt install vim
  58. ```
  59. test the power of the bash:
  60. ```bash
  61. > touch file.txt
  62. > echo "zap" >> file.txt
  63. > echo "dog" >> file.txt
  64. > echo "ape" >> file.txt
  65. > sort file.txt
  66. > sort file.txt > file-new.txt
  67. > sort file.txt | head -n 2
  68. ```
  69. ---
  70. References
  71. [^1]: Top 10 Unix Based Operating Systems, https://www.fosslinux.com/44623/top-unix-based-operating-systems.htm
  72. [^2]: Data science at the command line, 1st Ed,