Locked lesson.
About this lesson
In this video, we'll download and use our first data analysis tool: Numpy, which stands for Numerical Python.
Exercise files
Download this lesson’s related exercise files.
Pip Installing and Importing Numpy.docx57 KB Pip Installing and Importing Numpy - Solution.docx
55.7 KB
Quick reference
Numpy Overview - What is it used for
Numpy stands for Numerical Python and it does a lot of the heavy lifting math that we'll use.
When to use
You'll use numpy directly or indirectly from now on.
Instructions
Install Numpy from the terminal. Make sure your virtual environment has been activated and that you are in your /c/data directory; then issue this command:
pip install numpy
To use numpy, add it to our Jupyter Notebook with this line:
import numpy as np
Hints & tips
- pip install numpy
- import numpy as np
- 00:05 Okay, so we've got the main tools that we need installed.
- 00:08 We've got our Git Bash terminal, we've got our Jupyter Notebook set up, and
- 00:11 of course, we installed Python.
- 00:13 Now it's time to switch gears and install the first main data analysis tool that
- 00:18 we're going to use, and that is NumPy.
- 00:20 NumPy stands for numerical Python.
- 00:22 We'll talk about what it is, and how to use it in the next video.
- 00:26 In this video, we just want to install it and get it ready.
- 00:28 So, up until now we've downloaded things from websites like Python and
- 00:33 from the Git Bash terminal.
- 00:34 From now on, we're going to install things from the terminal like we did in the last
- 00:38 video with the Jupyter Notebooks.
- 00:39 And, NumPy is the first and the main one of those that we're going to use.
- 00:41 Now, I will say before we get started,
- 00:44 that NumPy is going to do a lot of the heavy lifting of our data analysis.
- 00:48 It's not something that's incredibly interesting.
- 00:51 It works kind of behind the scenes to move data around.
- 00:54 And we'll talk about all this in the next video, but first we need to install it.
- 00:58 So let's head back over to our terminal.
- 01:00 And you'll see that our Jupyter Notebook is running.
- 01:03 So let's hit the Ctrl and the C key at the same time on our keyboard, and
- 01:08 you can see it's shutting down.
- 01:09 And so our Jupyter Notebook has been turned off.
- 01:11 And it's kind of interesting to see if we head back over to our web browser, you see
- 01:15 we get this error, connection has failed, and our notebook doesn't work anymore.
- 01:19 And that's because it has to keep running in the terminal in order for
- 01:22 the Jupyter Notebook to work.
- 01:24 And we just turned it off in the terminal, so
- 01:25 it's turned off in the web browser as well.
- 01:28 So that's kind of interesting.
- 01:29 So I can go ahead and clear the screen if I want.
- 01:32 Now let's pip install NumPy.
- 01:34 And to do that, we just type in pip install.
- 01:37 And PIP, if you're not familiar, just stands for
- 01:39 the Python Installation Program, PIP.
- 01:41 And all it does is it installs Python modules and
- 01:44 tools that we're going to need for Python.
- 01:47 So pip install numpy.
- 01:49 And that's just NumPy, Numerical Python.
- 01:53 And when we do, it's collecting numpy, installing,
- 01:58 and should just take a couple of seconds, and boom we're done.
- 02:02 Now we can confirm that, if we want, by typing pip freeze.
- 02:06 And, remember, when we install Jupyter Notebooks, we install all of this stuff.
- 02:09 So we're going to have to kind of come through here and look.
- 02:11 And it should be In alphabetical order.
- 02:13 So just come down to the end section, and
- 02:16 then we see numpy 1.18.1 has been installed.
- 02:20 Now, if that's a different version by the time you watch this, no big deal,
- 02:23 just as long as it's the latest version, and
- 02:25 we can assume that it was the latest version because pip install always
- 02:29 installs the latest version unless you specify some other version to install.
- 02:32 So we can go ahead and clear the screen now.
- 02:35 And now we need to run our Jupyter Notebook one more time.
- 02:38 So I'm just hitting the up arrow key on my keyboard to sort of cycle through previous
- 02:42 commands that we've just done.
- 02:44 And we can come back to our Jupyter Notebook command, and I can hit Enter, and
- 02:48 boom that fires back up.
- 02:50 And you can see our screen has come back up.
- 02:53 I'm just going to come back over to this one, and hit Reload here.
- 02:57 And you'll notice this URL, I didn't really mention this in the last video,
- 03:00 but this is where we're going to be working from now on.
- 03:02 On this localhost:888/notebooks/ whatever the name of our notebook is.
- 03:09 And remember, we called ours data.
- 03:11 And 888 is just a port number that Jupyter Notebooks runs on.
- 03:16 And we don't really care what that means, it's just sort of interesting to note.
- 03:19 And then, in the future, to use our Jupyter Notebooks, we just run that
- 03:23 command that we just did in the terminal, and this jumps up, it fires up for us.
- 03:27 Or we could just open a web browser ourselves, manually, and type this in,
- 03:31 and that would work as well.
- 03:32 So, okay, let me get rid of some of this stuff here and
- 03:38 sort of start over with a fresh notebook.
- 03:41 So we've got a bunch of blank cells here.
- 03:43 Now we've installed NumPy.
- 03:45 But from now on, if we want to actually use NumPy,
- 03:49 we need to specify that right up here in our Jupyter Notebook.
- 03:53 And it doesn't have to be on the very top line like this, but
- 03:56 I like to put it there just because it's nice and clean that way.
- 03:59 But on any cell, really, you can put this command in.
- 04:03 And the command is import numpy as np, and then Shift Enter to run that.
- 04:10 And now we're good to go.
- 04:11 Now we can use NumPy in our Jupyter Notebook, as long as this
- 04:16 notebook is open, if we open a different notebook, we'll have to import this again.
- 04:20 But as long as we're using this data notebook that we created,
- 04:23 we can use NumPy.
- 04:24 And, like I said,
- 04:25 we're going to talk about in the next video exactly how to use this.
- 04:28 But the reason why we put this as np, so
- 04:32 that we can create a NumPy instance just by, from now on, calling np.
- 04:37 So we can go np., something, and we can do it.
- 04:42 You could name this anything you want up here.
- 04:44 You don't have to call this np.
- 04:46 You could call it jp, right?
- 04:49 You could call it hello, right?
- 04:51 But the convention is to call it np, is short for NumPy.
- 04:54 And it also makes it easier to retype it in, from time to time,
- 04:58 as we run NumPy functions and things going forward.
- 05:02 So that's all there is to installing NumPy.
- 05:04 Now we can use NumPy.
- 05:05 In the next video, I'll tell you sort of what NumPy is, how to use it,
- 05:09 why it's important, and we'll start actually doing some data analysis stuff,
- 05:13 and that'll be coming up in the next video.
Lesson notes are only available for subscribers.