How to Set up VS Code for Data Science & AI

Dave Ebbelaar
30 Jun 202222:53

Summary

TLDRIn this video, Dave, a data scientist, shares his experience with VS Code for data science projects, highlighting its advantages over Jupyter Notebooks in terms of workflow and productivity. He introduces VS Code, explains essential settings and extensions like Python, Pylance, and Jupyter, and demonstrates how to run Python code and Jupyter notebooks within VS Code. Dave emphasizes the efficiency of using VS Code for the entire data science project lifecycle, showcasing its interactivity and readiness for production.

Takeaways

  • πŸ‘‹ Introduction: Dave, a data scientist, introduces a tutorial on setting up VS Code for data science projects, which has improved his workflow and productivity.
  • πŸ› οΈ Tool Overview: VS Code is a free, integrated development environment (IDE) by Microsoft, compatible with Windows, Linux, and macOS, offering features like debugging, syntax highlighting, and intelligent code completion.
  • 🌟 Productivity Boost: Dave emphasizes VS Code's impact on his efficiency as a data scientist, allowing for the entire project lifecycle management without the need to convert Jupyter notebooks to Python files.
  • πŸ“š Extensions: The script highlights the importance of installing specific extensions for Python, such as the Python extension pack, Pylance, and Jupyter, to enhance VS Code's functionality for data science tasks.
  • 🎨 Customization: Dave discusses customizing VS Code with themes and settings, including workspace-specific settings that can override user-level settings for project-specific configurations.
  • πŸ” Interactive Coding: A key feature demonstrated is the ability to run Python code interactively within VS Code using the 'Jupyter send selection to interactive window' setting, combining the benefits of Jupyter notebooks with VS Code's features.
  • πŸ“ Code Management: Dave explains how VS Code facilitates easier code management for data science projects, making the transition from development to production smoother without the need for code duplication.
  • πŸ“š Workspace Setup: The script includes a step-by-step guide on setting up a workspace in VS Code, which helps in organizing and managing data science projects more effectively.
  • πŸ”„ Workflow Efficiency: Dave demonstrates the efficiency of using VS Code for data science by showing how to interactively run and test code segments, making the debugging and development process faster.
  • 🌱 Learning Resource: The video serves as an educational resource for those looking to enhance their data science workflow with VS Code, offering insights into extensions, settings, and best practices.
  • πŸ”„ Transition from Jupyter: The script highlights the benefits of transitioning from Jupyter Lab/Notebooks to VS Code for data scientists seeking a more efficient and feature-rich coding environment.

Q & A

  • What is the main topic of Dave's video?

    -The main topic of Dave's video is about setting up Visual Studio Code (VS Code) for data science projects and how it has improved his workflow and productivity.

  • Why did Dave switch from Jupyter Notebooks to VS Code?

    -Dave switched from Jupyter Notebooks to VS Code because it has significantly improved his workflow and productivity, offering more features and better support for the entire data science project life cycle.

  • What does Dave consider as the biggest advantage of using VS Code over Jupyter Notebooks?

    -The biggest advantage of using VS Code over Jupyter Notebooks is that it allows managing the entire data science project life cycle more efficiently, eliminating the need to transform notebooks into Python files for production.

  • What is VS Code according to Dave's introduction?

    -VS Code is a free, integrated development environment (IDE) made by Microsoft, available for Windows, Linux, and macOS, with features like debugging, syntax highlighting, intelligent code completion, and embedded Git support.

  • What are some of the must-have extensions Dave recommends for Python development in VS Code?

    -Dave recommends the Python extension pack, which includes Python (essential for running Python code), Intellicode (an AI assistant for Python development), an environment manager, Python indent fixer, and Docstring.

  • What is the purpose of the 'Jupyter' extension in VS Code?

    -The 'Jupyter' extension allows users to work with Jupyter Notebooks within VS Code, providing the benefits of both Jupyter and VS Code environments.

  • How does Dave demonstrate the interactivity of running Python code in VS Code?

    -Dave demonstrates the interactivity by showing how to run selected lines of code in a Python file using the 'Jupyter: Send Selection to Interactive Window' feature, which allows for an interactive session similar to Jupyter Notebooks.

  • What is the significance of the 'Pylance' extension mentioned in the script?

    -The 'Pylance' extension is a feature-rich language server for Python in VS Code that enhances the autocompletion suggestions and IntelliSense capabilities, making Python development more efficient.

  • How does Dave use workspace settings in VS Code to customize his projects?

    -Dave uses workspace settings to override user settings specific to a project, allowing for project-specific configurations that are saved within the VS Code workspace file.

  • What is the 'Jupyter Send Selection to Interactive Window' setting in VS Code and how does it help in data science projects?

    -The 'Jupyter Send Selection to Interactive Window' setting allows users to send selected code from a Python file to a Jupyter interactive window instead of the Python terminal, enabling an interactive way of running and testing code blocks during data science projects.

  • How does Dave suggest using the interactive window feature in VS Code for data transformation?

    -Dave suggests using the interactive window to test and validate parts of the data transformation function by selecting and running specific lines of code to check the output, ensuring the correctness of the transformation before applying it to the entire dataset.

Outlines

00:00

πŸ˜€ Introduction to VS Code for Data Science

Dave, a data scientist, introduces the video's focus on setting up VS Code for data science projects. He explains the benefits of using VS Code over Jupyter Notebooks and Labs, highlighting improved workflow and productivity. The video will cover an introduction to VS Code, personal themes and settings, essential extensions, running Python code, and using Jupyter Notebooks within VS Code. VS Code is praised for its features like multi-language support, debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git.

05:01

πŸ› οΈ Setting Up VS Code with Extensions and Themes

The paragraph details the process of setting up VS Code for data science, starting with installing the Python extension pack which includes essential tools for Python development. Dave discusses the importance of Intellicode for AI-assisted code completion, improving speed and accuracy. He also mentions other extensions like Pylance for enhanced Intellisense, and the Jupyter extension for integrating Jupyter Notebooks within VS Code. Additionally, he covers changing themes and icon themes to personalize the VS Code environment.

10:04

πŸ“ Organizing Data Science Projects in VS Code

Dave demonstrates how to organize a data science project in VS Code by creating a workspace, which allows for project-specific settings. He explains the difference between user-level and workspace-level settings and their implications for project organization. The paragraph emphasizes the convenience of workspace settings for maintaining a consistent project environment across different sessions.

15:04

πŸ”„ Combining Jupyter Notebooks and Python Files in VS Code

The paragraph explains how to work with Jupyter Notebooks and Python files in VS Code. Dave shows how to open and run a Jupyter Notebook within VS Code using the Jupyter extension. He also discusses the advantage of running Python files interactively using the 'Send Selection to Interactive Window' setting, which allows for testing and validating code sections without rerunning the entire script, thus mimicking the interactivity of Jupyter Notebooks.

20:06

πŸš€ Enhancing Productivity with Interactive Python Script Execution

Dave illustrates the productivity benefits of using VS Code for data science by interactively running sections of a Python script. He demonstrates how to validate a data transformation function step by step, emphasizing the speed and efficiency gained from this method. The paragraph highlights the seamless integration of interactive execution with the robust features of VS Code, resulting in a workflow that is both productive and enjoyable.

🌟 Conclusion and Call to Action

In conclusion, Dave reflects on the significant improvement in his productivity and coding experience after transitioning from Jupyter Lab and Notebooks to VS Code. He encourages viewers to subscribe to his channel for more data science-related content and thanks them for watching. The paragraph serves as a summary of the benefits of using VS Code for data science and an invitation for viewers to follow for further insights.

Mindmap

Keywords

πŸ’‘Data Science

Data Science is a field that involves extracting knowledge and insights from data, often large datasets, through various statistical and computational techniques. In the video, the theme revolves around setting up a development environment for data science projects, emphasizing the importance of a tool like VS Code in enhancing the workflow and productivity of a data scientist.

πŸ’‘VS Code

VS Code, short for Visual Studio Code, is a free, open-source, and highly customizable integrated development environment (IDE) made by Microsoft. The video highlights VS Code's features and how it has transformed the presenter's data science workflow, offering a more efficient and productive coding experience compared to Jupyter Notebooks.

πŸ’‘Extensions

In the context of VS Code, extensions are add-ons that enhance the functionality of the editor, allowing for additional features and support for different languages and tools. The script mentions several must-have extensions for Python and data science, like the Python extension pack and Jupyter, which are crucial for setting up VS Code for data science tasks.

πŸ’‘Integrated Development Environment (IDE)

An IDE is a software application that provides comprehensive facilities to computer programmers for software development. The video introduces VS Code as an IDE and discusses its benefits for data scientists, such as supporting multiple languages, offering debugging tools, and having a marketplace for extensions.

πŸ’‘Jupyter Notebooks

Jupyter Notebooks is an open-source web application that allows creation and sharing of documents containing live code, equations, visualizations, and narrative text. The video compares the traditional use of Jupyter Notebooks with the presenter's new workflow using VS Code, highlighting the productivity gains made by the switch.

πŸ’‘Python

Python is a high-level, interpreted programming language widely used for general-purpose programming, including data science. The video emphasizes the importance of the Python extension in VS Code, which is essential for executing Python code within the IDE and managing Python environments.

πŸ’‘Debugging

Debugging is the process of finding and resolving bugs or defects that prevent a computer program from working correctly. The video mentions VS Code's debugging features as one of the reasons it is favored for data science, allowing for more efficient problem-solving and code refinement.

πŸ’‘Syntax Highlighting

Syntax highlighting is a feature of text editors that displays text, especially source code, in different colors and fonts depending on the category of terms. The video script mentions syntax highlighting as one of the features of VS Code that contributes to a better coding experience.

πŸ’‘Intelligent Code Completion

Intelligent code completion, also known as IntelliSense, is a feature that suggests possible code completions as the programmer types. The video describes how this feature in VS Code, powered by extensions like Pylance, speeds up coding and reduces errors, which is particularly beneficial in data science projects.

πŸ’‘Workspace

In the context of VS Code, a workspace is a set of settings and configurations associated with a specific project or folder. The video demonstrates how to save a workspace in VS Code, allowing for project-specific settings and a more organized workflow for data science projects.

πŸ’‘Code Refactoring

Code refactoring is the process of restructuring existing computer code without changing its external behavior to improve nonfunctional attributes of the software. The video script briefly mentions code refactoring as one of the features of VS Code, which can be useful for maintaining and improving the quality of code in data science projects.

Highlights

Introduction to setting up VS Code for data science, emphasizing its impact on workflow and productivity.

Brief overview of VS Code as a free IDE by Microsoft, available on multiple platforms.

VS Code's features such as multi-language support, debugging, syntax highlighting, and intelligent code completion.

The extensibility and customizability of VS Code, with a vast marketplace for extensions.

Productivity benefits of VS Code over Jupyter Notebooks, including project lifecycle management.

Demonstration of creating a workspace in VS Code for project-specific settings.

Importance of the Python extension pack for running Python code within VS Code.

Explanation of Intellicode as an AI assistant for Python development in VS Code.

The convenience of extensions like Pylance for enhanced autocompletion and Intellisense.

Jupyter extension that allows running Jupyter Notebooks within VS Code.

Customization options for themes and icon themes in VS Code to suit personal preferences.

Workspace and user settings distinction in VS Code for project-specific and global configurations.

The 'Jupyter: Send Selection to Interactive Window' setting for interactive Python code execution.

Combining the interactivity of Jupyter Notebooks with the functionality of VS Code for efficient coding.

Example of using VS Code for data transformation and validation within a Python script.

The productivity gains from using VS Code's interactive window for step-by-step data science projects.

Final thoughts on the advantages of VS Code for data science, including code readiness for production.

Transcripts

play00:00

welcome everyone today i have another

play00:02

exciting new video for you guys uh first

play00:04

of all my name is dave i'm a data

play00:07

scientist and in this video i will show

play00:10

you how to set up fies code for data

play00:12

science this is something that has

play00:13

completely changed the game for me

play00:15

coming from working with jupiter

play00:17

notebooks and jupiter lab which are

play00:20

awesome tools by the way but vs code has

play00:22

totally changed the game for me in terms

play00:23

of my workflow and my productivity so in

play00:26

this video i'll show you how i've set up

play00:28

my fuse code and i use it for my data

play00:30

science projects right so here's what

play00:32

we'll cover in this video

play00:34

i'll first give a brief introduction

play00:35

about field code then i'll go over some

play00:38

themes and settings that i personally

play00:40

use then some must have extensions for

play00:43

if you want to write biting code then

play00:44

i'll show you how to run python code

play00:46

using field code and lastly i will show

play00:49

you how you can also run jupyter

play00:51

notebooks within fields code all right

play00:54

so what is fies code so for those of you

play00:56

that don't know it's a free integrated

play00:58

development environment or ide for short

play01:02

made by microsoft

play01:04

and it's available for windows linux

play01:06

macos so doesn't matter what system

play01:08

you're using you can install fies code

play01:11

for free and get started now why do i

play01:14

like vs code first of all because it has

play01:16

so many features it supports many

play01:18

languages it has a really good features

play01:20

for debugging syntax highlighting

play01:23

intelligent code completion this is a

play01:25

big one

play01:26

snippets code refactoring and uh

play01:29

embedded git within it so that's really

play01:31

convenient for version control what also

play01:33

makes it really awesome is the

play01:35

extensibility and the customizability so

play01:38

there are many

play01:39

many settings and there's a huge

play01:41

marketplace with extensions to add new

play01:44

languages teams debuggers etc and you

play01:47

really have to know a few settings and

play01:48

extensions to make it work for writing

play01:51

python code and doing data science

play01:53

projects and then productivity since

play01:55

i've made the switch to fierce code

play01:57

coming from jupiter lab jupiter

play01:59

notebooks it has just made me so much

play02:01

more efficient as a data scientist and

play02:03

then this is probably the biggest

play02:05

advantage of using vs code versus just

play02:08

uh jupiter notebooks or jupiter lab it's

play02:11

that you can manage the entire data

play02:12

science project life cycle and this also

play02:15

has to do with with just productivity as

play02:17

i just mentioned when you first write

play02:19

your code in a jupiter notebook and then

play02:21

once it's ready for production you have

play02:23

to transform that notebook into a python

play02:25

file and that just takes a lot of time

play02:27

basically have to write your code twice

play02:30

and vs code makes this so much easier

play02:33

and i will show you how to do that so

play02:35

first of all if you don't have fierce

play02:37

code you can just google it go to the

play02:39

website and you can download it install

play02:41

it for free alright let's now hop into

play02:43

vs code and i'll show you how i've set

play02:45

up mine to work on data science projects

play02:48

so

play02:49

i've opened up a blank field code file

play02:52

we'll start off by going to top right

play02:54

corner file and opening a folder so i've

play02:58

made a demo folder for this video which

play03:00

i will open it has a typical data

play03:03

science project

play03:05

layout so it has some data

play03:07

we have some code and some python code

play03:10

and we have some notebooks let me close

play03:12

this out for now and the next thing that

play03:14

i will do once i've imported the folder

play03:17

is i will save it as a workspace so i go

play03:21

to file save workspace as

play03:23

and

play03:24

i'll just save it here as demo which is

play03:27

fine what i've just done is i've saved

play03:29

this file with

play03:31

the imported folder as a vs code

play03:33

workspace file and within this workspace

play03:37

you can save settings that are

play03:39

particular to this project so that could

play03:42

be really convenient and another nice

play03:45

way of working like this is that now

play03:47

once i want to work start working on a

play03:49

project again i can just open up the

play03:52

workspace file and it will open up vs

play03:54

code within this workspace with all my

play03:57

folders attached so now we've set up the

play04:00

project so now how do you get started as

play04:03

i mentioned when you just downloaded vs

play04:06

code it's kind of blank it's kind of

play04:08

empty so we need to add some extensions

play04:10

and we to have to tweak some settings in

play04:13

order to make it work for us so let's

play04:15

hop into the extensions and you can do

play04:18

this by clicking on this icon in the

play04:20

left bar over here

play04:22

and this will first show you a list of

play04:24

all the extensions that you currently

play04:26

have installed as you can see these

play04:27

these are all my extensions that i'm i'm

play04:30

running and there also is a search bar

play04:32

where you can search for extensions so

play04:35

first and foremost

play04:37

what we'll start with is the python

play04:40

extension back

play04:42

this is basically a must-have pack that

play04:45

installs uh

play04:46

six different packages that i think are

play04:49

just very convenient some of them are

play04:51

necessary to run python code within vs

play04:53

code so on the overview over here you

play04:55

basically have a description of

play04:58

what's in the in the extension and

play05:01

i already have this extension pack

play05:02

installed so

play05:04

for me it says disable uninstall but for

play05:06

you when you don't have it installed

play05:09

there will be an install button over

play05:11

here so you can just do that install it

play05:13

it's free it will take a couple of

play05:15

seconds and it will stall install the

play05:17

following extensions

play05:19

to fuse code so i'll quickly go over

play05:22

what these are so first of all python

play05:25

is essential to run python code so this

play05:28

is a extension that is produced by

play05:31

microsoft so this basically enables you

play05:33

to run python code and here you can see

play05:35

you can manage your

play05:37

environments which version of python you

play05:40

are using so this is a must-have so

play05:43

what's uh what else is in it then we

play05:46

have intellicode which

play05:48

is very awesome this is and i just

play05:51

explained how this is

play05:53

not so good within jupiter lab and

play05:54

jupiter notebooks but this is just

play05:56

basically makes your life as a data

play05:58

scientist easier it's an ai assistant

play06:01

python development tool that

play06:03

autocompletes suggest etc so you can see

play06:05

an example here of what it does whenever

play06:08

you start typing intellicode will prompt

play06:11

some suggestions

play06:12

and using the arrow keys you can toggle

play06:15

through them and then just hit enter and

play06:17

it will auto complete the code so this

play06:20

will do two things

play06:22

it will make you write code faster and

play06:24

it will also make sure that you make

play06:27

less errors because you don't have to

play06:29

type all the

play06:30

methods and the attributes

play06:32

by hand and you can just auto complete

play06:34

them so

play06:36

that in turn will also

play06:38

enable you to just work faster all right

play06:41

so what else is in it there's an

play06:44

environment manager

play06:46

django comes uh with it if if you work

play06:48

with django that's really uh convenient

play06:51

uh this is the extension to fix python

play06:53

indents uh automatically also very

play06:55

convenient and then you have outer dock

play06:57

string which is also a cool tool this uh

play07:01

basically what this does if you type

play07:03

three quotes it will insert a dog string

play07:06

template which is very important to just

play07:08

comment your functions and your codes

play07:11

for yourself but also when you're

play07:13

working with other people alright so

play07:15

that's the python extension pack

play07:17

let me take a look at my notes yes so

play07:20

the next one that we're looking into is

play07:24

by lance so let me just look it up

play07:26

pylance same thing here i've already

play07:29

have it installed

play07:30

you can install it over here basically

play07:32

what pylance is it's a feature rich

play07:35

server language in python for vs code

play07:38

and it basically it works together with

play07:40

intellisense so as it says here pylance

play07:43

has the ability to supercharge your

play07:45

python intellisense basically this makes

play07:47

the autocompletion suggestions etc even

play07:50

better

play07:51

so another really nice extension to have

play07:55

and then lastly jupiter and

play07:58

this is a wrong tab

play08:00

this is

play08:01

a really cool extension that basically

play08:04

gives you the best of both worlds so i

play08:07

will show you later how this works but

play08:08

basically this allows us to use all the

play08:11

uh the benefits from jupiter and jupiter

play08:14

notebooks within fies code so jupiter

play08:17

over here install it as well those are

play08:19

like the the essentials and there's a

play08:22

lot more

play08:23

code snap is also a pretty

play08:25

funny tool that you can use to

play08:28

make pretty

play08:29

code export so you can highlight a

play08:31

section of code and then export it to to

play08:33

a jpeg for example so i sometimes use

play08:35

this for presentations pretty cool

play08:39

path intelligence you can look into

play08:41

basically makes working with bots

play08:44

easier so when you type double quotes

play08:46

you can look through your parts and

play08:48

easily look up data data files for

play08:50

example but yeah that's just about it

play08:53

about the extensions oh no wait one more

play08:56

thing you can also look for teams and

play08:59

icon teams

play09:00

within the

play09:02

marketplace so if you want to tweak some

play09:05

settings and adjust the look and feel of

play09:07

this code you can do that here so for

play09:10

example i know that atom has a has a

play09:12

team for example so

play09:14

yeah you can look that up check if it

play09:16

fits fits your vibe

play09:18

how you do that once you've installed

play09:21

the theme you can go

play09:23

to the settings in the

play09:25

lower left corner here and by clicking

play09:27

on the gear icon and then you can hit

play09:29

color team and this will show you all

play09:31

the themes so i can basically just

play09:33

scroll through those and you can see how

play09:35

it how it will change and when you

play09:38

install a theme from the marketplace it

play09:41

will show up here so let me just i use

play09:43

the dark plus default dark this is the

play09:46

one i like so this is how you switch up

play09:48

your teams and another cool thing

play09:51

is you can change your icon

play09:54

theme if i click here file icon team i

play09:56

think the

play09:58

you can disable them and i think this is

play10:00

like the default or maybe this one these

play10:03

are from vs code itself so you have

play10:05

minimal and set eye and you can see on

play10:07

the left on the left over here what what

play10:09

it does so

play10:10

um i use the material icon team and why

play10:14

i do that is uh what i really like about

play10:16

this team is that it creates different

play10:19

folders for

play10:21

different

play10:22

depending on the name of the folder so

play10:24

here you can see data has a little

play10:25

database icon docs as doc items

play10:27

different color and the models has a

play10:29

different

play10:31

different color and a different icon so

play10:33

and the source is in green with the code

play10:35

icon next to it so basically this allows

play10:38

me to really easily look up folders that

play10:41

i want to check so not just by name but

play10:44

also by color and it's i think it just

play10:45

adds a little nice touch and now there's

play10:48

one uh more thing i want to show you

play10:50

about the settings um so if i go to

play10:54

settings over here now first of all

play10:56

there are a ton of settings that you can

play10:58

tweak from font sizes to

play11:02

whatever you can

play11:03

look through all of these i have almost

play11:06

everything just on default i've also

play11:08

never really looked in

play11:10

too much of it because i like

play11:13

the way it comes out of the box but

play11:15

there's one important thing

play11:17

to note here and that is that you have a

play11:20

user level and a workspace level and

play11:23

basically how this works is

play11:26

on the user level everything that you

play11:28

tweak will be saved within ps code and

play11:31

then once you open up a new file and you

play11:34

open up a new project by default it will

play11:37

look at the user level uh you can

play11:39

basically compare this to just your your

play11:41

settings in any uh program you just

play11:44

change them and when you open up a new

play11:46

instance of the program your settings

play11:47

are still there but then a really

play11:50

convenient thing is that you also have

play11:53

workspace settings and workspace

play11:55

settings override your usb user settings

play11:59

and they are tied to the workspace so as

play12:02

i showed in the beginning of this video

play12:03

i imported this folder and then i saved

play12:07

this this project to this workspace now

play12:10

this workspace contains settings and for

play12:13

example if i want to increase the font

play12:16

size over here so let me just check i

play12:18

can if i click here and here you won't

play12:20

see any difference but here i will make

play12:22

adjustments on a user level and here i

play12:24

will make adjustment to just the

play12:27

workspace level that is a distinction

play12:29

that you have to be aware of all right

play12:31

so and there's one setting

play12:34

that i want to show you and

play12:37

this is really cool and we'll check that

play12:38

out in a bit and that is the jupiter

play12:40

send selection to interactive window and

play12:44

i will do that on the user level and i

play12:46

will look for jupiter sent to

play12:49

so jupyter send selection to interactive

play12:51

window we want to check this button over

play12:54

here and what this does as it describes

play12:56

here when pressing shift enter send

play12:58

selected code in a python file to the

play13:00

jupyter interactive window as opposed to

play13:02

python terminal and i will show you

play13:05

later in this video what this will do

play13:07

but this is awesome all right now that

play13:10

we've set up fierce goat with the

play13:12

settings and the extensions i'll now

play13:14

show you why it's so awesome and give

play13:17

you a few examples

play13:19

so let me first start by

play13:21

opening up a notebook and by the way

play13:23

this is just a notebook some notebooks

play13:26

that i downloaded from this github

play13:28

repository over here it's just some

play13:29

basic bandless exercises

play13:32

and what i can do is let me just open it

play13:35

up and and here you can see that we can

play13:37

just open up a jupyter notebook and also

play13:40

just run it just like we're used to so

play13:43

this is really awesome and this works

play13:45

because we have installed the jupiter

play13:47

extension and now we can basically just

play13:50

work like any other notebook in the top

play13:53

right corner over here we can select our

play13:55

environment so i'm using anaconda and my

play13:58

base environment and this is really

play14:00

awesome so we can just um

play14:02

work on jupiter notebooks here and let

play14:05

me just open this up in the finder it's

play14:07

just a notebook file and what we can do

play14:09

if i just open this up and open like a

play14:12

regular jupiter session you can see this

play14:14

this is basically just the same as you

play14:16

would normally work but now we're doing

play14:18

it in fields code so that is how you

play14:20

work with jupyter notebooks within vs

play14:22

code and now i'll show you how to work

play14:24

with python files and something that has

play14:27

completely changed the game for me in

play14:28

terms of my productivity so let me close

play14:32

this and i'll open up a quick python

play14:34

file here very basic file we import

play14:36

pandas we load a data frame and we print

play14:39

the data so the main difference between

play14:42

working with jupiter notebooks and

play14:44

working with python files is that in

play14:46

jupyter notebooks you run code sell by

play14:49

cell which is very convenient you can

play14:51

use breakpoints and you can basically

play14:53

for for data science projects you can

play14:55

very easily manage a project step by

play14:58

step so you first load the data you

play15:00

check it you do some explorations you

play15:02

tweak some things and this is really

play15:04

convenient because in a data science

play15:06

project you constantly go back and forth

play15:09

back and forth so you load the data you

play15:10

do some tweaks visualize something

play15:13

create a function back and forth and

play15:15

iterate until you have your desired

play15:18

output so that's what makes a jupyter

play15:20

notebook very convenient for that and if

play15:23

you compare this to running just python

play15:25

file for example that we have over here

play15:28

we can do run python file is it will run

play15:31

everything

play15:32

in one go so it will import the library

play15:35

it will load the data and then it will

play15:37

print the head of the data in this case

play15:40

but the thing is say for example you're

play15:42

working with quite a big data set you do

play15:44

some transformations that maybe take a

play15:47

couple of seconds each

play15:49

and then you've noticed that all the way

play15:50

at the end your

play15:52

visualization doesn't really work you

play15:55

mess it up

play15:56

now if you were working in a python file

play15:59

you would have to adjust your code and

play16:01

then rerun that entire python file and

play16:04

do all those transformations again so

play16:06

load the data etc and this can take a

play16:09

couple of seconds sometimes even minutes

play16:11

every time that you run the file and a

play16:14

jupyter notebook counters this by

play16:16

running it in codeblocks but now by

play16:19

using vs code we can get the best of

play16:22

both worlds and i'll show you how to do

play16:24

this so remember the setting

play16:26

that we tweaked within the settings is

play16:29

jupiter

play16:30

sent

play16:31

so it says here when pressing shift

play16:33

enter

play16:34

send the selected code in python file to

play16:37

a jupyter interactive window as opposed

play16:39

to the python terminal what this

play16:41

basically means is that we can now

play16:43

within the python file as you can see

play16:45

this is not a notebook but this is a

play16:46

python file we can select a line of code

play16:49

and then hit shift and enter

play16:51

and vs code will fire up a interactive

play16:55

jupiter session so this is basically the

play16:57

same thing that's running in the

play16:58

background whenever you're running a

play16:59

jupyter notebook and it will store the

play17:03

lines of code that you've run within

play17:05

memory so

play17:06

you can see for example here the

play17:08

variables no there's nothing over here

play17:10

but then once we load the data

play17:13

so i can either select the line

play17:16

or i can just have my cursor on one of

play17:19

the lines and hit shift enter

play17:21

what you can see it will run this line

play17:23

of code and then it will store it into

play17:26

the variables so what this basically

play17:28

means is that we can write our python

play17:30

code but run it in an interactive

play17:34

way just like we would do in jupyter in

play17:36

a jupyter notebook all right and i'll

play17:38

show you why this is so awesome and how

play17:40

you can use this in like a regular data

play17:42

science project so i have a little

play17:44

script here that basically reads some

play17:46

data then there is a function

play17:49

to transform some of the data and then

play17:51

to store it so this is like the the

play17:53

typical first step within a data science

play17:56

project i will set my cursor on the

play17:57

first line and hit shift enter to fire

play18:00

up an interactive window that's

play18:02

completed so then i go to the second

play18:04

line and import the data and what i can

play18:07

then do i can just select the data and

play18:09

then run it so this is so convenient for

play18:13

working on a python script is i can just

play18:16

use

play18:17

my arrows and then select

play18:19

certain variables or select whole lines

play18:23

to run the code so if i have my cursor

play18:25

just on this line or i select the whole

play18:27

line i can run it and then what i can do

play18:30

i can just move my cursor forward then

play18:32

select just data and then run it and it

play18:35

will show me the output and this just

play18:37

makes it so fast to to work through

play18:40

through a code and you also don't have

play18:43

to

play18:43

um for example in a notebook insert a

play18:46

line below then type data there and then

play18:48

check the output you can just run this

play18:50

very interactively and it's yeah it's

play18:53

just very a very natural way of writing

play18:55

code

play18:57

also you have all the

play18:59

tools

play19:00

in the toolbar here that you

play19:02

also have in the jupyter notebook so for

play19:03

example i can clear everything up let me

play19:06

show you another cool thing so i have a

play19:08

data transformation function here that

play19:11

basically takes the data and let me just

play19:13

show what data is

play19:15

and it takes the item price and it

play19:17

basically turns it into a float so as

play19:19

you can see it has a it has a dollar

play19:21

sign here and that makes it a an object

play19:25

within panda so we can't do any uh

play19:27

calculations with it so this would be

play19:30

like a typical data transformation and

play19:33

i've

play19:34

defined this this function and then what

play19:36

i can do here is i can

play19:38

call this function put data variable we

play19:41

didn't and then we have our data

play19:43

transformed but what you would typically

play19:45

do is you write this function

play19:48

line by line and in between you test a

play19:51

few things so what i can now do is

play19:53

instead of just

play19:55

running this whole function i can just

play19:57

go to

play19:59

this particular section highlight it

play20:01

and then check whether the output is

play20:03

correct so i can start off with the item

play20:05

price

play20:06

and as you can see this is just the item

play20:08

price from

play20:09

the data data frame and this is an

play20:12

object and then i can use the string

play20:14

that replace method so i'll select

play20:17

this over here and i can check

play20:19

all right this works the dollar sign is

play20:21

now

play20:22

gone but it's still an object and then i

play20:25

can say okay but now we want this as a

play20:27

float so we run

play20:30

we add s-type float to the end run it

play20:33

and boom now you can see dollar sign is

play20:35

removed and pandas recognized it is

play20:38

recognizes it as a float alright so now

play20:42

i've basically validated

play20:44

my function i'll select it i'll run it

play20:47

the function is now defined so i can see

play20:50

this is a function what i can then do is

play20:52

i run the line over here and then now my

play20:55

data transformed is a new data frame

play20:58

which has the item price as a float so

play21:01

yeah this has completely changed the

play21:03

game for me in terms of my my

play21:04

productivity and

play21:06

once you get used to this way of working

play21:08

it just becomes so fast you can just

play21:11

hop through your code using the arrow

play21:12

keys and then make selections by

play21:15

using command or control and shift and

play21:18

highlighting certain parts or by using

play21:20

alt or option for example then basically

play21:22

you have the best of both worlds so you

play21:24

have the interactivity of going back and

play21:27

forth

play21:28

of jupiter notebooks but you also have

play21:31

the added functionality of vs code in

play21:34

the extensions to write in a python file

play21:37

uh with all the added features that we

play21:39

discussed like the auto completion uh

play21:42

and the suggestions to basically speed

play21:45

up your coding make less errors etc and

play21:48

you combine those and it will just

play21:50

really improve your workflow it has at

play21:52

least done uh for me as i already

play21:54

mentioned the best thing is that the

play21:56

code that you're writing is also ready

play21:59

for production because it's in in a

play22:01

python file and not in a jupyter

play22:02

notebook so you don't have to do that

play22:04

transformation so that's what i wanted

play22:06

to show you in today's video this is how

play22:09

i use and set up vs code for my data

play22:11

science project as i said it has

play22:13

completely changed the game for me

play22:15

coming from jupiter lab jupiter notebook

play22:17

switching to the workflow that i just

play22:20

explained over here i'm just way more

play22:22

productive and can write code

play22:24

way faster it's also way more fun i

play22:26

think so

play22:27

yeah um i hope this video helped you out

play22:30

if it did i would really appreciate it

play22:32

if you like this video subscribe to the

play22:35

channel

play22:36

i'll be sharing more videos related to

play22:37

data science basically whenever

play22:40

i encounter something in my work

play22:42

that i think can help other people i

play22:44

will try to create a video about it

play22:47

so yeah if that's something you're

play22:48

interested in definitely subscribe

play22:50

thanks for watching see you next time

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
VS CodeData SciencePythonJupyterProductivityWorkflowIDE SetupCoding TipsExtensionsAutocomplete