In Part 2 of our Jupyter Notebook Tutorial series, we will learn installing packages in Jupyter, importing data, plotting inline etc works. Our Part 1 of Jupyter Notebook Tutorial was on how to install on localhost or server – on Mac OS X or GNU/Linux. For quick recapitulation to unused with Python, normally on terminal, if you run :
1 |
python |
then it will start Python interactive command shell like this :
1 2 3 4 |
Python 2.7.13 (default, Jun 24 2017, 02:53:00) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> |
To obtain current directory, we first will run :
---
1 |
import os |
then :
1 |
os.getcwd() |
To exit that shell, we will type :
1 |
exit() |
If you type :
1 |
ipython |
you’ll get enhanced interactive Python shell.

Jupyter Notebook Tutorial : Part 2
Now open Jupyter Notebook on browser like we talked in Part 1 of this series. On the right hand side there will be a “New” dropdown menu. If you click it, that first option will be “Python3” (which you’ll normally click to start works), other options includes a terminal. You’ll see the input field :
1 |
In [ ] |
Copy paste this :
1 |
print("The answer is", 2*2) |
then click the RUN button, which should return “The answer is 4”. If you want a LaTeX output, run this :
1 2 |
from IPython.display import display, Math, Latex display(Math(r'sqrt{a^2 + b^2}')) |
For the next steps of guides, you need to install :
- Pandas
- NumPy
- SciPy
- Plotly
- matplotlib
via pi. For Mac OS X appendicectomy sudo -H
before the commands and run :
1 2 3 4 5 |
pip install pandas pip install numpy pip install scipy pip install plotly pip install matplotlib |
pip install numpy
will show that previous command already installed it. Now again freshly launch Jupyter notebook with the command :
1 |
jupyter notebook |
In that Jupiter notebook’s input, enter this and run, which is example of using Plotly :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import plotly.plotly as py from plotly.graph_objs import * import pandas as pd mapbox_access_token = 'pk.eyJ1IjoiY2hlbHNlYXBsb3RseSIsImEiOiJjaXFqeXVzdDkwMHFrZnRtOGtlMGtwcGs4In0.SLidkdBMEap9POJGIe1eGw' json_data = pd.read_json('https://raw.githubusercontent.com/ottlngr/2016-15/ottlngr/ottlngr/sites.json') rating_one_site_lat = [] rating_one_site_lon = [] locations_name = [] for index in range(len(json_data)): if json_data['locations'][index] != []: if json_data['site'][index]['rating'] == 1: rating_one_site_lat.append(json_data['locations'][index][0]['latitude']) rating_one_site_lon.append(json_data['locations'][index][0]['longitude']) locations_name.append(json_data['site'][index]['name']) data = Data([ Scattermapbox( lat=rating_one_site_lat, lon=rating_one_site_lon, mode='markers', marker=Marker( size=18, color='rgb(155, 240, 225)', opacity=0.7 ), text=locations_name, hoverinfo='text' ), Scattermapbox( lat=rating_one_site_lat, lon=rating_one_site_lon, mode='markers', marker=Marker( size=8, color='rgb(205, 245, 100)' ), hoverinfo='skip' )] ) layout = Layout( title='Nuclear Waste Sites on Campus', autosize=True, hovermode='closest', showlegend=False, mapbox=dict( accesstoken=mapbox_access_token, bearing=0, center=dict( lat=38, lon=-94 ), pitch=0, zoom=3, style='dark' ), ) fig = dict(data=data, layout=layout) py.iplot(fig, filename='jupyter/Nuclear Waste Sites on American Campuses') |
Here’s what we’ve got for you which might like :
Additionally, performing a search on this website can help you. Also, we have YouTube Videos.
Take The Conversation Further ...
We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!
If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.
Contact Us