Data Science: Best Vscode settings
Tags: python, datascience, vscode, jupyter
Published: 2022-10-27 11:30:00


VS code has become the tool for any programming project and data science is one of them. Most data scientists like to use jupyter notebook or jupyter lab but what they don't know is VS Code support jupyter notebook and you can do much more than just use jupyter notebook. one of the best feature of vscode for data science is **Interactive python window** will talk about that later, lets talk about some other features. 

## 1. IntelliSense
> IntelliSense is a general term for various code editing features including: code completion, parameter info, quick info, and member lists. IntelliSense features are sometimes called by other names such as "code completion", "content assist", and "code hinting."

![IntelliSense](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hh4zrug426ax1ihu67cb.png)

When we install python extension for vscode it comes with IntelliSense and it works as intended. You can improve IntelliSense with type annotation in your project. 

![IntelliSense with type annotation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5u4v7ezd6mp23lhvys9.png)

As you can see in above image there is no suggestions for the name parameter but as soon as we define type of parameter vscode will show all the available methods related to the datatype (below image).

![suggestions for the name parameter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4dhvhvxu278fdghygufv.png)


## 2. Indent (Space vs Tabs)
> At the end of the day, tabs versus spaces is truly a matter of preference, however the tab is still the character specifically designed for indentation, and using one tab character per indentation level instead of 2 or 4 spaces will use less disk space / memory / compiler resources and the like.

It depends on individual, I prefer tab and set it as 2 space (2 column) width as it occupies less space and I only have to key only one time and every stroke matters. To change indent size in vscode follow below steps...

![Tabs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hlqfzp03ejpsltkpspb1.png)

![2 tabs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/553d1zveawmtikam4owg.png)


## 3. Text Warp
Most of us don't prefer text to run off the screen. To toggle wrapping on or off on a per-file basis, simply press `ALT + Z` . If you almost _never_ want to turn text-wrapping off, you can make it the default. Inside `settings.json`, simply paste in the following code, and your text will wrap by default:
```json
{ "editor.wordWrap": "on" }
```

## 4. Evaluate Math Expression
You know vscode have inbuild calculator? You can evaluate basic math operation. Just select the expression, press `ctrl+shift+p` and search for "Evaluate and you will find the option".

![Evaluate Math Expression](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwmupa5pcu47cv304c76.gif)

## 5. Format on Save
Install *[black](https://github.com/psf/black)*, a python formatter that will help us follow a similar formatting for all our data science projects. command:
```bash
pip install black
```

Open your VSCode settings, by going 'Code -> Preferences -> Settings'. Search for "python formatting provider" and select "black" from the dropdown menu:


![Code -> Preferences -> Settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/crrvyg2tqol0411x54a0.png)

In the settings, search for "format on save" and enable the "Editor: Format on Save" option:

![Editor: Format on Save](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cs9odxazdqp2xax1jia1.png)


## 6. Snippets 
You can install extensions for snippets but you can also define your own snippets. With this features you can type few character to type repeated code like imports statements, plotting functions etc.

![Snippets](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u57rgjnjubjrly1ss5m2.gif)



## 7. Interactive Python Window 
VSCode support interactive python window, where you can run python code just like jupyter notebook but even better as your main code is stored in a single python file. This is a very important and productive features for data scientist. For this to work you need to change the setting with...
```json
"jupyter.sendSelectionToInteractiveWindow": true // <---- Very Important
```

![Interactive Python Window](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/podkglmtwbx69z2vyk76.gif)


## 8. Remote access to VMs

Odds are that you’ll run code in a server, a virtual machine or some other hardware that you might want to connect to via SSH. Fortunately, you can connect to any of them and still carry on using your local VS Code installation, by using the [Remote SSH](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) extension.

## 9. CSV

As a data scientists you have to deal with a lot of file types that stores the data, CSV is the most famous file type to store huge amount of data. As CSV is a txt file so you can open it directly in vscode but to make it more usable and readable we can use extensions such as...

1. [Rainbow CSV](https://marketplace.visualstudio.com/items?itemName=mechatroner.rainbow-csv) which will provide highlighting for your csv file..

![Rainbow CSV](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ijjs19ne6pgchvegdegr.png)

2. [Edit csv](https://marketplace.visualstudio.com/items?itemName=janisdd.vscode-edit-csv) which has a excel like UI to edit and update your csv file.

![Edit csv](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/asmg6q6qe104ywpzgdoa.gif)


As the article is getting longer we will talk about some more settings in future articles so make sure to follow the series to not miss any updates. If you have anything to say comment down below I'm new to blog writing so any type of feedback is appreciated Thanks.