Running Python Code - The Next Level: IPython and Jupyter Notebook

Python 3: Automating Your Job Tasks Superhero Level: Automate Data Analysis Tasks with Python 3
9 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€92.19
List Price:  €129.06
You save:  €36.87
£78.58
List Price:  £110.01
You save:  £31.43
CA$136.67
List Price:  CA$191.35
You save:  CA$54.67
A$150.59
List Price:  A$210.84
You save:  A$60.24
S$134.92
List Price:  S$188.90
You save:  S$53.97
HK$780.74
List Price:  HK$1,093.06
You save:  HK$312.32
CHF 91.36
List Price:  CHF 127.90
You save:  CHF 36.54
NOK kr1,064.83
List Price:  NOK kr1,490.80
You save:  NOK kr425.97
DKK kr687.94
List Price:  DKK kr963.14
You save:  DKK kr275.20
NZ$163.14
List Price:  NZ$228.40
You save:  NZ$65.26
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳11,726.90
List Price:  ৳16,418.13
You save:  ৳4,691.23
₹8,323.81
List Price:  ₹11,653.68
You save:  ₹3,329.86
RM470.40
List Price:  RM658.58
You save:  RM188.18
₦144,735.52
List Price:  ₦202,635.52
You save:  ₦57,900
₨27,863.65
List Price:  ₨39,010.23
You save:  ₨11,146.57
฿3,652.73
List Price:  ฿5,113.97
You save:  ฿1,461.24
₺3,221.22
List Price:  ₺4,509.83
You save:  ₺1,288.61
B$515.31
List Price:  B$721.46
You save:  B$206.14
R1,838.13
List Price:  R2,573.45
You save:  R735.32
Лв180.33
List Price:  Лв252.47
You save:  Лв72.14
₩136,328.34
List Price:  ₩190,865.12
You save:  ₩54,536.78
₪367.16
List Price:  ₪514.04
You save:  ₪146.88
₱5,817.18
List Price:  ₱8,144.28
You save:  ₱2,327.10
¥15,665.20
List Price:  ¥21,931.91
You save:  ¥6,266.71
MX$1,664.50
List Price:  MX$2,330.37
You save:  MX$665.86
QR364.97
List Price:  QR510.97
You save:  QR146
P1,352.70
List Price:  P1,893.83
You save:  P541.13
KSh13,248.67
List Price:  KSh18,548.67
You save:  KSh5,300
E£4,709.52
List Price:  E£6,593.52
You save:  E£1,884
ብር5,750.98
List Price:  ብር8,051.60
You save:  ብር2,300.62
Kz84,938.73
List Price:  Kz118,917.63
You save:  Kz33,978.89
CLP$89,860.01
List Price:  CLP$125,807.61
You save:  CLP$35,947.60
CN¥710.98
List Price:  CN¥995.41
You save:  CN¥284.42
RD$5,874.34
List Price:  RD$8,224.32
You save:  RD$2,349.97
DA13,453.05
List Price:  DA18,834.81
You save:  DA5,381.76
FJ$226.58
List Price:  FJ$317.23
You save:  FJ$90.64
Q777.82
List Price:  Q1,088.99
You save:  Q311.16
GY$20,943.47
List Price:  GY$29,321.70
You save:  GY$8,378.22
ISK kr13,838.61
List Price:  ISK kr19,374.61
You save:  ISK kr5,536
DH991.17
List Price:  DH1,387.67
You save:  DH396.50
L1,767.86
List Price:  L2,475.08
You save:  L707.21
ден5,684.36
List Price:  ден7,958.33
You save:  ден2,273.97
MOP$804.86
List Price:  MOP$1,126.84
You save:  MOP$321.97
N$1,819.29
List Price:  N$2,547.09
You save:  N$727.79
C$3,684.41
List Price:  C$5,158.32
You save:  C$1,473.91
रु13,334.80
List Price:  रु18,669.25
You save:  रु5,334.45
S/373.79
List Price:  S/523.33
You save:  S/149.53
K389.03
List Price:  K544.66
You save:  K155.63
SAR375.02
List Price:  SAR525.05
You save:  SAR150.02
ZK2,610.17
List Price:  ZK3,654.34
You save:  ZK1,044.17
L458.69
List Price:  L642.19
You save:  L183.49
Kč2,277.99
List Price:  Kč3,189.28
You save:  Kč911.28
Ft35,684.59
List Price:  Ft49,959.85
You save:  Ft14,275.26
SEK kr1,068.91
List Price:  SEK kr1,496.52
You save:  SEK kr427.60
ARS$88,989.05
List Price:  ARS$124,588.23
You save:  ARS$35,599.18
Bs691.73
List Price:  Bs968.45
You save:  Bs276.72
COP$381,035.35
List Price:  COP$533,464.74
You save:  COP$152,429.38
₡51,327.13
List Price:  ₡71,860.04
You save:  ₡20,532.90
L2,473.92
List Price:  L3,463.59
You save:  L989.66
₲753,154.66
List Price:  ₲1,054,446.66
You save:  ₲301,291.99
$U3,830.21
List Price:  $U5,362.45
You save:  $U1,532.23
zł393.43
List Price:  zł550.82
You save:  zł157.39
Already have an account? Log In

Transcript

Hi, and welcome to this section of the course. During this section you will learn yet another very useful skill related to Python and task automation. And that is data analysis. Data Analysis is a very large and complex topic that can be approached from several perspectives by a Python programmer. One of the best and most comprehensive Python modules is specially designed for the purpose of analyzing and handling data is called pandas. And we will work with pandas a lot throughout the next videos.

However, before getting our hands dirty and diving into data analysis, let me show you two very useful tools that you can use instead of the classical Python interpreter. Why are these tools so important now at this point into the course? Well, that's because they bring some very nice features and enhancements compared to the Python interpreter we've used thus far into the course one These new features is the improved displaying of big chunks of data in the form of nicely formatted and organized tables, as you're going to see throughout this section, okay, in our theory, now let's get to work. The tools I told you about are called ipython, and Jupiter, let's install and see them one by one starting with ipython. To install ipython, just open up the windows command line, and type in pip install ipython. In my case, I have already installed it.

So I want to do it again, wait for the setup to be complete. And that's it. Now you can use ipython by simply typing in ipython in the windows command line. So let's go ahead and do that right now. ipython. Now you can see that as in the case of the default Python interpreter, we have some information displayed right above the prompt.

So right here we have the current version of Python being displayed some basic commands to get more information and help, and also the version of ipython currently being installed. In my case, this is 7.2 point zero. However, in your case, these versions may slightly differ depending on when you are watching this video. Nevertheless, the content residing in this section stays relevant. Next, you can notice a different prompt than the one we're used to from the default Python interpreter. This green prompt labeled as in means that it expects some input from you.

For instance, let's enter the copyright command. So copy right. Notice that after hitting Enter, the command is executed and we get a different prompt or read one this time, labeled as out. Meaning of course that the text following it is the output of the command or line of code above. And then we have the output itself as expected. This one right here.

Notice one more thing here. The number in between square brackets, we have one for both in and out, meaning that this was the first command or line of code that was executed. And that this output right here corresponds to this input, both being marked with the same identifier one. Next, we can see that ipython now expects the second input from the user. Let's have a dictionary printed out to the screen. First, let's create the dictionary and I'm going to copy and paste it to avoid wasting any time writing it.

Okay, this is the dictionary. Now let me hit enter. Notice that after hitting Enter, we are redirected to the next input prompt marked with the number three, since there is no output to be shown as a result of creating our dictionary, which is correct, right. On the other hand, if we now choose to print out the value that the my dict variable points to, meaning the dictionary itself, we expect to have an output, obviously, so let's do this. My dict and as I said, this time, we have an hour returned and printed out to the screen corresponding to the Associated input the name of the variable. Another important thing to notice here is that ipython does a great job of formatting and displaying data sets, like for instance, our dictionary right here.

To see this enhancement better, let's open up the plain old Python interpreter and create and print out the same dictionary. So I'm going to paste in the same dictionary. And now let's print it to the screen. Of course, the difference is quite obvious. And using ipython instead of the idle Python interpreter can prove to be a great decision when working with data and data sets. This is going to become even more obvious in the next videos, where we are going to load larger chunks of data from Excel, CSV, JSON or text files, but more on that later.

Now let's talk about the second tool I was referring to at the beginning of this video, and that is Jupiter notebook. By the way, you can find links to the official documentation have both these tools in the text lecture following this video. For now let's start by installing Jupiter for this just open up the windows command line again. In my case, I'm going to hit exit. And now you should type in pip install Jupiter. Again, I have already installed this tool on my system, but you should go ahead and press enter and wait for the installation to be complete.

Now to work with Jupiter notebooks, all you have to do is type in Jupiter notebook in the command line, however, let's not do that just yet. Instead, let's create a new folder. I have already created that folder on my D drive. It's called Jupiter and it is currently empty. So we have created this new folder. And this is the folder where we are going to store our notebook.

Now inside the windows cmd. Let's move to the newly created folder. So I'm going to delete this. Let me move this a bit. Okay, so I'm going to type in de Colon to move to the D drive. And now let's change the current directory to the directory I just shown you so Jupiter.

And now let's run the command here. So Jupiter notebook. Notice that after pressing Enter, we get a new browser window opened. This session is hosted on the local host using Port 8888. As you can see up here in the browser bar, now it's time to create our first Jupiter notebook. As a side note, please keep in mind that Jupiter is basically an open source web application born out of the ipython project, and built to support much many programming languages other than Python.

So back to our notebook. Let's click on new and Python three, a new browser tab opens up and you can already notice that this prompt right here looks awfully similar to the ipython prompt we've seen earlier. Right First of all, Let's assign a name to this notebook. So I'm going to call it test one, rename. And now if I check my folder on the D drive, the Jupiter folder, there is a new notebook that has been created right here, test one.ip, y and B, where this extension stands for IPython notebook. Now back to the browser, let's create the same dictionary that we used before.

So I'm going to paste it here. Once again. At this point, I can either execute this line of code by pressing Ctrl plus enter, or just use the Enter key to add a new line of code to the same cell. So I'm going to press enter and add a new line for instance, print of my dict. Now control plus enter runs the code inside this cell, and then the dictionary is printed out to the screen. Okay, what now?

What if you want to add a new cell to the notebook? Well, it's as simple as pressing ALT Enter, and there is your new cell. Let's write some code in this cell. For instance, let's say print of List of range of 10. And now I will show you how to run the code inside this cell and also create a new cell at the same time. It's easy just use shift plus enter.

So Shift Enter. And as you can see, the code has been executed and we are automatically moved to a new cell. Pretty cool right? You will see the true power of Jupiter in the next videos. When we are going to start working with data and tables. You will understand why Jupiter is such a great tool for data analysis compared to the default Python interpreter or even to the command line version of ipython.

You can find all the keyboard shortcuts for Jupiter in the Help menu right here by pressing keyboard shortcuts. However, the shortcuts we discussed in this lecture are the most frequently used ones and you will need them whenever you're going to use Jupiter For now, I hope you enjoyed learning about these two very useful tools for data analysis and I will see you in the next lecture.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.