r/learnpython • • Mar 05 '21

Jupyter Notebooks - Great tool for beginners

Just wanted to share with anyone who is struggling to learn AND implement code. I'm in my 4th week of Intro To Python and I have to say, I got a little overwhelmed. My teacher recommended using Jupyter Notebook (Google it, it's Free!) and it's helped out a shitload. Basically it's an open-source web app that allows you to share documents that contain live code. The BEST part is you can easily toggle between text for note-taking and code AND RUN THE CODE right in the document. This really changed the game for me and if you're out there struggling to bounce between your notes and your interpreter/compiler, check it out. Good luck

378 Upvotes

72 comments sorted by

90

u/aussievolvodriver Mar 05 '21

Jupyter is a great tool when you're doing the initial design but just be careful, it can encourage bad code practices because you can swap up and down in the different cells and it can hurt in the long run if you don't realise it.

I'd suggest once you get the code working practice putting it in a script, you'll quickly learn how to do scripts without reaching for notebooks and development will be faster.

29

u/[deleted] Mar 05 '21

The best way to do this is to have jupyter set up with the autoreload magic so that it is constantly importing your script. Then once a function or something is working, it goes to the script right away rather than only moving it all at the "end" of a project.

5

u/BoJackHorseMan53 Mar 05 '21

This seems out of the blue. What are you referring to?

19

u/[deleted] Mar 05 '21

Beginners have this problem of coding in notebooks where they will do things like define a function in cell 3, use it in cell 2, and they have their notebook break next time they try to use it. They often fail to realize the only reason it worked before was because they ran the cells in a particular order. The user above was suggesting putting it all in a script at some point in order to avoid some of these confusions/bad practices.

I was pointing out that, rather than trying to define functions and classes inside your notebook, you should start by developing them in a script which is then automatically reimported into your notebook. This allows you to move things into the script bit by bit, rather than trying to move whole chunks all at once and running into many issues related to out of order execution, having to document everything with docstrings all at once at the end, doing all the testing at the end, etc etc.

→ More replies (1)

8

u/[deleted] Mar 05 '21

Either that or use the fast forward button on the toolbar every time you add a new code block. That was particularly fun to do on this project where I had to load 3GB of data each time I restarted the kernel.

In seriousness: I think jupyter's purpose ought to be mostly didactic or expository. In my physics courses I always have a running notebook for any computational problems or notes.

But I am glad that my first contact with python was through spyder. Understanding why jupyter works or doesn't work was much easier after understanding consoles, kernels in the context of an IDE. You can't really use a hammer right if you don't know that the nail is meant to be pushed in.

2

u/Useful-Pomelo Mar 05 '21

I am really struggling to see the difference between a .py file in Spyder and a reason to use Jupyter Notebooks. Notebooks seem more linear, first this, then that; while a .py file can have branching and conditionals and loops.

2

u/BoJackHorseMan53 Mar 05 '21

You can write everything you'd write in a .py file in a single Jupyter notebook cell and it'd work.

→ More replies (5)

2

u/[deleted] Mar 05 '21

Thisss^

25

u/tomanonimos Mar 05 '21

For Jupyter notebook, it's a great tool for a beginner to learn syntax. But it has the potential to set a lot of bad habits for a beginner. Jupyter runs python code differently. Imo all good Python habits can be used in Jupyter but not all good Jupyter habits are good for Python IDE

23

u/[deleted] Mar 05 '21

Jupyter Notebooks are great - check out their implementation in VS Code: https://youtu.be/FSdIoJdSnig

1

u/hurler_jones Mar 05 '21

Thanks for sharing this! I'm just starting my journey into python and using Zero to Hero which uses Jupyter in the course. I had already dabbled a little with VS Code and I like the little that I explored already (grafana and homeassistant - just enough to be dangerous as they)

I will be checking this out as soon as I have some time.

0

u/[deleted] Mar 05 '21

[deleted]

6

u/Mr_Wynning Mar 05 '21

Try using the insider edition, they've essentially rewritten their Jupyter implementation from the ground up and it's significantly better.

1

u/[deleted] Mar 05 '21

Ah interesting, I didn’t realise! FYI here’s the GitHub issue for that request: https://github.com/microsoft/vscode-jupyter/issues/1227

31

u/[deleted] Mar 05 '21

I work on a combined analytics & data science team ... Jupyter Notebooks isn’t just great for beginners. It’s pretty ideal for collaborating and sharing code and outputs.

7

u/HasBeendead Mar 05 '21

Its good for data visualization , clearly.

12

u/tomanonimos Mar 05 '21

It depends. And data visualization isnt a strong argument for Jupyter notebook. What makes jupyter notebook a super useful tool is that when you send it out to ppl, it saves the outputs. So at the very least the receiver knows what to expect from the code.

4

u/yuckfoubitch Mar 05 '21

THIS. You don’t have to rerun every line of code which could matter a lot if you’re doing some machine learning algorithms that can take a long ass time to run.

7

u/expressly_ephemeral Mar 05 '21

Be aware of its disadvantages. Great tool for EDA (Exploratory Data Analysis), but not great for making anything like a finished product.

6

u/GrandBadass Mar 05 '21

I think one of the major advantages of Notebooks is that it's almost kind of like a built in debugger. When you are learning it is nice to see where your code is failing instantly. I also think the cells really also allow for building functions separately from the area where you execute your functions. I think that if used well, it can help you build clean/organized code. I really enjoy Notebooks.

Edit - added some clarification

11

u/Biuku Coding since April 2020 Mar 05 '21

100%.

When Chrome came out you could suddenly search in the browser bar. Seems trivial, but a hugely intuitive change I'd struggle to go without now.

Jupyter gives instant feedback. Running code right where you type it is great for drilling new concepts, experimenting, unit-testing parts of larger blocks of code. It's a way more intuitive way to try new things.

1

u/TBRosati Mar 05 '21

Wow I did not expect this post to get so much attention. A lot of cool ideas and tips! I'm liking this community already. Thanks everyone

9

u/ectomancer Mar 05 '21

I use it for LaTex.

Try jupyter lab.

5

u/Biuku Coding since April 2020 Mar 05 '21

What's the advantage of Jupyter Lab? I'm into trying it, but very attached to how things work in the basic version now.

4

u/carlhines Mar 05 '21

It’s a bit more shiny, you can see your files on the left side instead of in a different tab and if you have multiple notebooks open, you have tabs within the tab of the jupyter tab and not in the browser. So imo everything looks a bit more tidy. On the downside matplotlib does not work in interactive mode

3

u/[deleted] Mar 05 '21

I use %matplotlib qt backend and the plots open in separate pop-up windows, where I can interact with them just fine. Maybe give that a shot

4

u/[deleted] Mar 05 '21

Oh baby... A file explorer on a pane within the app, where you can also shut down kernels with two clicks, self-contained tabs for notebooks within the app, not in the browser. You can copy cells, drag&drop between notebooks (instead of selecting text, ctrlC ctrlV it between tabs). You can install and manage plug-ins for all types of purposes. And it has dark mode.

→ More replies (1)

2

u/johnnymo1 Mar 05 '21 edited Mar 05 '21

Lots of advantages, but one of my favorite features is having a console linked to a notebook kernel, so if I want to see the value of a variable after a cell executes, I can just type var or whatever its name is into the console rather than having cells that just say var or print(var) littering my notebook.

EDIT: Also, as someone else mentioned... dark mode.

1

u/baubleglue Mar 05 '21

mutli-user mode if you work in a team

2

u/Biuku Coding since April 2020 Mar 05 '21

Bold of you to think I have friends.

But thank you.

→ More replies (1)

9

u/[deleted] Mar 05 '21

Its great. Also google has a similar platform named google colab. Ive been using it for a python course at work and is wonderful.

2

u/Nemaeus Mar 05 '21

I believe Netflix dropped their own in 2019 or 2020. Haven’t looked at it in awhile but seemed interesting at the time.

2

u/StressedSalt Mar 05 '21

i used to use it when i was a fresh beginner and i actually really disliked it Hahah

2

u/bpt7594 Mar 05 '21

Lol my entire department's projects are written using Jupyter Notebook. And I work for a bank.

2

u/emsiem22 Mar 05 '21

Just use them as much as you like. Some comments here are counterproductive. Only way you can lose this is if you stop. So do what brings most joy and you'll progress.

2

u/yourcsprofessor Mar 06 '21

I use it right now because of pandemic, it makes everything a little easy being remote. If you ever have questions on it reach out!

2

u/chrome9k Mar 06 '21

I am a heavy jupyter user professionally. It is addicting instant gratification to run code cells. This comes with a huge risk of bad habits. Try to balance your time evenly between .ipynb and .py development the best you can. Otherwise, code refactoring nightmares galore!

1

u/KeeZouX Mar 05 '21

Yes. My Doctor (PhD) also recommended it.

1

u/Fenr-i-r Mar 05 '21

I enjoyed the notebook format and jupyter lab, but am really glad to have migrated to an actual IDE and script files. Vscode let's you run code in notebook cells, so it has all the advantages of the rapid testing of jupyter, but at the end of the day you have a nice script, and a full fledged ide.

Make the transition when you are ready.

1

u/thekalmanfilter Mar 05 '21

I tried it but I don’t know here to start. Been using PyCharm so far though

1

u/Buckeyefan123 Mar 05 '21

Yeah, my "teacher" started us using Jupyter and tbh since I don't really use any programming in day-to-day job duties I still have trouble properly creating python environments. It is good for certain use cases don't get me wrong but I think I leaned on it for too long and hurt myself in the long run.

1

u/AK1174 Mar 05 '21

i kinda wish someone had told me about it back when i was learning Python. It would have helped a ton and made the process a lot more well.. clean and less cluttered.

1

u/HighO1 Mar 05 '21

I will not suggest Jupyter Notebook for beginners ,it will hurt in longer run. Learn whole python in some kind of editor like sublime or you can use IDEL python and then if you want to learn pandas, numpy and any visualization libraries than use Jupyter notebook.

1

u/aDistractedDisaster Mar 05 '21

I used Jupyter, but have you tried VSCode or Google Colab notebooks?

1

u/MerviElina Mar 05 '21

I know some R and I just started learning Python as a hobby. I'm having a hard time setting up a Python IDE. I'm trying to do it in Atom but I was wondering if Jupyter is easier. R Studio has been extremely helpful on my R journey. Is Jupyter similar to R-studio?

3

u/spacemonkeykakarot Mar 05 '21

Spyder is the closest thing to RStudio.

JupyterLab is okay too, but it's not like RStudio.

RStudio also supports Python now IIRC.

1

u/MerviElina Mar 06 '21

Thank you! Haven't heard about Spyder before, I'll check how it looks. I just noticed that I can create new Python scripts or add Python chunks in RStudio. It looks I can just keep using RStudio!

2

u/sardonicsheep Mar 05 '21

Jupyter is much more intuitive and beginner friendly than RStudio IMO. I say that as someone who’s spent much more time in Rstudio.

1

u/MerviElina Mar 06 '21

Interesting! I found RStudio pretty easy to navigate. I'm glad Jupyter is even more beginner-friendly because this time I don't have a teacher.

1

u/Tawpigh Mar 05 '21

I use JN on main because I'm more familiar with it than R and it fits in niceley with my geospatial workflow to handle most of the tabular data analysis but also because the people who taught me Python did so using Jupyter Notebooks.

It's a convenient teaching tool and a lot of in-class and udemy courses use it as do many Indian programming experts on YouTube

1

u/stackhat47 Mar 05 '21

Google collab needs no Installation and does the same thing at a basic level

1

u/SkoalGally Mar 05 '21

Genuinely curious - why is there no love for Google Colab?

1

u/Almostasleeprightnow Mar 05 '21

Although a lot of good points in this post about the downsides and bad habits gained through using Jupyter as an intro tool, I think something like this kind of tool is going to be absolutely crucial in allowing more types of learners to become literate in coding, which is something that will probably be important in the next few decades.

1

u/[deleted] Mar 05 '21

Any suggestions for moving away from Jupyter to something more mature? I like notebooks for the easy visualization but I don’t find it to be very feature rich in terms of tiling. Not sure if I just missed that module or I hit a limitation.

1

u/slowcanteloupe Mar 06 '21

Also get nbextensions for jupyter. Helps you keep things clean and organized and adds a lot of functionality.

1

u/Theonetheycall1845 Mar 05 '21

It is really neat

1

u/srichey321 Mar 05 '21

I agree. I use Jupyter for initial design, testing and it is great if you are a beginner.

1

u/[deleted] Mar 05 '21

I love it too. My workflow is basically writing/testing a block of code in a Notebook, exporting it to a script, importing the functions, and then continuing to the next block.

1

u/[deleted] Mar 05 '21

If you like jupyter notebooks, then I think you'll love jupyter lab. Work with multiple notebooks in a self-contained environment, edit other text files, open images, etc etc. You can even copy-paste whole cells between notebooks (not just the text in the cells).

AND IT HAS DARK MODE. JUPYTER LAB DOESN'T KILL YOUR EYES AT NIGHT!

To add to all this, I suggest using it in tandem with the Open-as-Popup chrome extension. It basically becomes an app on its own and not a tab in your browser!

0

u/BoJackHorseMan53 Mar 05 '21

Just gonna write my thoughts after having experience of 2 years with python and Jupyter.

Jupyter notebook is a great tool for beginners and when you're writing small pieces of code. It can accelerate the learning process. It's easier to run a cell than running a python file and you can always run your code and then when it runs into an error, check out all the variables that might be causing the error and fix them then run only the remaining code compared to a .py file where you have to run the whole code again. If you're lazy like me, you can skip writing print() to print variables, just write the variable name and execute.

But once you become advanced with python and build applications, Jupyter notebook isn't suitable for that. If you're writing modules to import to other python files, you have to use a .py file. If you're building web apps using frameworks like flask, you have to use .py file. You can't run a Jupyter notebook from terminal or schedule it in crontab for example. In my experience, Jupyter notebook gets difficult to manage with longer code files and I only use it to test out something quickly or when I'm learning a new thing in python.

After starting with Jupyter notebook and coding in it for a year, I switched to VS Code now that I write larger programs. It's my favorite code editor. I've tried others like atom, jetbrains pycharm, sublime and settled with vscode.

In conclusion, all the big boys write code in .py files and newbies like Jupyter notebook.