Jupyter
Jump to navigation
Jump to search
This page is meant to be a startup guide for using Jupyter Notebooks with Python. It assumes you have installed Anaconda from https://www.anaconda.com/. Most of this guide was written running Python 3.9 and Jupyter Notebooks 6.4.12.
Starting Up
To start Jupyter Notebooks with Anaconda:
- On Windows, go to the Anaconda folder in the Start Menu or open the Anaconda Navigator and start from there.
- On macOS, open the Anaconda Navigator and start from there.
Tutorial
There's a great tutorial at https://www.dataquest.io/blog/jupyter-notebook-tutorial/! A few notes:
- CTRL-Enter runs the current cell; SHIFT-Enter runs the current cell and provides a new empty cell below it. SHIFT-Enter is generally the way to go
- ESC and ENTER toggle between command mode and edit mode. In edit mode, there is a pencil icon at the top right; in command mode, there isn't. Also, if you click in the edit part of a cell you enter edit mode; if you click in the space between the In []: and the >| you enter command mode.
- In addition to the commands shown, Markdown understands basic LaTeX (Greek letters, fractions, integrals, etc). Use single $ around commands for inline and $$ around commands for displaymath.
- For the commands that print formatted strings, the tutorial uses the string modulo method. To relate this to using format, and also to using the new (as of Python 3.6) f-string, here are three ways of printing the same information:You can see that all three are similar; the f-string puts the variable at the same location it will end up printing in the string rather than way at the end.
# string modulo print('%d squared is %d and %0.2e squared is %0.2e' % (a, b, c, d)) # format print('{:d} squared is {:d} and {:0.2e} squared is {:0.2e}'.format(a, b, c, d)) # f-string print(f'{a:d} squared is {b:d} and {c:0.2e} squared is {d:0.2e}')
- The "Setup" section in the middle of the page starts to go into some advanced data analysis with Pandas; they always give you the code, but it may be confusing! Also:
- You will need to have saved their data file to the folder where you are saving your notebook. The file is in the "Example Data Analysis in a Jupyter Notebook" section way at the top of the page, or you can get it from https://s3.amazonaws.com/dq-blog-files/fortune500.csv.
- There needs to be a carriage return after "import seaborn as sns"