Data Science with Jupyter Notebooks

Interactive data science with Jupyter notebook


The way I run Python code live on the screen is by using a Python package called Jupiter. Jupyter is built into the IPython project and allows Interactive Python to run in your browser. But it is more than that. From special command "magic" and bash commands to plugins, Jupiter greatly enhances the Python coding experience.


If you are already using Jupiter, I hope I can improve your workflow and show you some new tricks. If you are not yet using Jupyter, then log in.



Installation and startup

The easiest way to install Jupiter is to install the pipe using Jupiter, although if you use a package Python distribution like Anacondo, you may have already installed it. Be sure to activate your Python environment first. We dive.


When you turn on Local Jupyter, you'll connect to a locally running webserver through your browser, usually on the 8888 port. Start your notebook by running Jupiter Notebook in your work directory. Normally Jupiter will open automatically once it starts, but if not, show your browser to local host: 8888 point.


If you don't already have a notebook that you want to open, you can create one by clicking on a new one and selecting Python 2 or ing, depending on the version of Python you're running in the environment. Jupiter is quite flexible and can actually handle many languages ​​and file types, although we will only stick with Python for now.


Code running on Jupiter notebook

Once you have a new notebook, you can write some Python code in the blank cell and just use ctrl + enter. We can run all our specific Python code here, just like you would write in Python script. The difference is that we can run it and see the results now!


Notice what happens when we run a cell with a ctrl + enter. The bracket to the left of the cell shows the asterisk when the cell is running or queuing to move the key, and then it shows a number after the end, which cells were starting at '1' in the given session respectively.


The result of the last line of the code cell will be printed as the output of that cell, but only if the value is not stored in the variable. For example, if I import TensorFlow and then connect it with a string, the output is shown below, even if I don't use the print command.


Of course, I can also use print (). It’s all very useful for tinkering and seeing how some behave.


Shift-tab


Another great feature of the Jupiter notebook is the ability to display the document of the function you called by pressing the Shift-tab. This allows you to call a function with the correct arguments.


This feature also works with your own local customization functions, so if you write good documents, you will be rewarded!


Results


When you have a lot of output, you can reduce the amount of space you take by clicking on the left panel of the output, which turns it into a scroll window. If you double-click, the output will be completely destroyed.


More cells!


One cell is useful, but we really want more cells. To add a cell, click the 'plus' icon in the toolbar. There are also some cell execution commands that can create new cells.


If you press Shift + Enter, it will play the current cell and highlight another cell. If there is no new cell, then a new cell is created. On the other hand, if you want to create a new cell immediately after a given cell, you can use Alt-enter to execute the cell and then insert a new cell behind it.





Did anyone say markdown?


Probably the biggest feature I've ever left is the Markdown support. My first impression of the Jupyter notebook was the ability to provide both writing code and a great way to describe the code I wrote. Markdown's rich economics allows researchers and educators to communicate ideas and ideas together easily and clearly.


And perhaps most importantly, it allows you to predict the future in the past - what a given code cell should do, in a way that can be more expressive than using comments!








Jupyter Magics


Sometimes I want to quickly check how long it takes to implement a training or assessment cycle. For an easy way to find the time of your code, start the cell with% 10 times and once the cell execution is finished it will print how long it took to run the cell. It's not the exact atomic time, but it's the perfect way to get some solid first impressions with very little effort.


If you want to run a command-line command on a notebook, the easiest way is to put an exclamation point in front of the command. This is most useful for a single off order.


If you want to run a group of commands, start the cell with '%% bash' to interpret the whole cell as a bash script.


One of its best uses is to kick the tensorboard. To run Tensorboard you usually need to start a new terminal window and run it on the command line, which we usually do if you want to run it for a while. But if you just want to turn it around, take a look, and turn it off, putting it in the Jupiter notebook cell isn't such a bad idea.


Plus, you'll never forget to run it, as it integrates into your workflow of notebook cells! Note that this will keep your notebook. So you can't move anything else while the tensorboard is running. To stop this, click on the block kernel, the asterisk will be removed, and you will get back control flow.


So there you have it, my favorite Jupyter features and capabilities. This is certainly not a detailed discussion of Jupiter's features. I've just done my favorite cover and mostly used it here. There are many, many more waiting for your exploration.



Comments