Data Science and Data Proicessing

Visual Studio Code for Data Science — the Power User’s guide

The quintessential IDE?

Visual Studio Code
Source: Visual Studio Code on Wikipedia

Microsoft’s Visual Studio Code is arguably one of the best IDEs for developers. The same is true for Data Scientists. There are numerous tools and extensions in the VS Code that enable users with great user experience.

Setup

Install the Python for VS Code extension

For R, install R extension

Environments

Often, you will require packages and modules that are not available by default installation. Some libraries or applications specify a particular version of a library to be used. Virtual environments are useful in these cases.

You can setup Python using Python distributions using Anaconda.

To manage your environment, in VS Code, you can select an environment of your choice from the Command Palette ( ⇧⌘P ) > Python: Select Interpreter.

Image for post
Python: Select Interpreter
Image for post
Selecting a Python environment

Workspaces

Workspace Settings are stored inside your workspace and only apply when the workspace is opened. They override the global user settings. This way each of the Data Science workspaces can be custom configured.

Jupyter Notebooks

Jupyter

The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text.

Developed as a successor to IPython with REPL (Read-Evaluate-Print-Loop) shell, Jupyter Notebooks are the computational notebook of choice for Data Science.

The Jupyter extension is not being maintained currently, and the Python plugin from Microsoft officially includes native support for Jupyter Notebooks.

Install Jupyter

Install Jupyter in your workspace using pip install jupyter

To create a new Jupyter notebook — use the Command Palette ( ⇧⌘P ) > Create New Blank Jupyter Notebook.

Image for post
Open a new Jupyter Notebook

The Jupyter server will be set to local, and a python kernel is selected based on your workspace settings.

Image for post
Jupyter Notebook toolbar

Extensions

Extensions are an integral part of the Visual Studio Code experience for developers. They range from visual effects to integration with other services. You can modify your interface as much as you wish to enhance productivity, for example —Bracket Pair Colorizer helps you find that one missing or extra bracket with colors, or Trailing spaces can help you find the extraneous spaces, which is really helpful in python.

For a list of extensions that can improve your experience on Visual Studio Code, I found the following medium post really helpful.

Some of the extensions include:

  • Trailing spaces
  • Bracket Matching
  • GitLens
  • Sublime Text KeyMap
  • Intellisense

Integrated terminal

Image for post
Integrated Terminal

Visual Studio has an integrated terminal, that starts at the root space by default.

To open the terminal:

  • Use the ( ⌃` ) keyboard shortcut with the backtick character.
  • Use the View > Terminal menu command.
  • From the Command Palette ( ⇧⌘P ), use the View: Toggle Integrated Terminal command.

Managing multiple terminals

Terminal instances can be added by clicking the plus icon on the top-right of the TERMINAL panel or by triggering the ( ⌃⇧` ) command.

Split terminals

You can also split the terminal by triggering the ( ⌘\ ) command or via the right-click context menu.

Version Control

Git
Source: unDraw

Version control is essential for any developer or project, helping facilitate working on different modules and versions by across teams. Git, the distributed version control system for tracking changes in your source code is neatly integrated into Visual Studio Code.

Git in VS Code
Git History (git log)

To get started with Git on VS Code, download and install the official extension names — GitHub Pull Requests and Issues. Or you can install the extension GitLens. GitLens helps you to visualize code authorship via Git blame annotations and code lens, and navigate and explore Git repositories.

Follow me on LinkedIn and GitHub, or visit my website at rohithsajja.me

+ Recent posts