#25 AI for Good Specialization [Course 1, Week 2, Lesson 2]

A walkthrough of the Week 2 lab on air quality data using Jupyter Notebook. Learn how to import Python packages, read a CSV dataset, convert datetime fields, and run cells with Shift+Enter. The instructors also cover common errors like indentation problems and how to reset the lab.
Chapters
In this video, I'll be walking you through the beginning of the first lab and demonstrating some of the features of the jupyter notebook environment that you'll be working with. If you'd like to follow along as I go through this, you can go ahead and open up the lab itself in another browser tab, or if you're already familiar with a Python programming environment, jupyter Notebook environment, you can feel free.
To skip ahead to the next video. When you're in this course, you can find this particular lab inside week two here where it says Lab air quality, explore the data and then when you click Launch Notebook, your lab will open up the new browser tab that will look something like this. This is a really popular format for prototyping programming applications known as a jupyter notebook, which is an open source web application that you can use to create and share documents that contain code, visualizations and text. From now on, I'll be referring to this environment simply as your web notebook and so you can scroll down for a quick look at what's in this notebook. You'll notice that there are blocks of text and blocks of code, and in general, the text will include instructions or descriptions of what the code is doing. As you run each of the code cells, you'll see some output from the code. In general, the notebook will be in a folder with some other files like data sets and other code files, and you can see what else is in the folder by clicking up here on the jupyter icon. So in this case we have a folder with the data in it, and this file right here is the same data set we were looking at in the spreadsheet in the last video. It is now shown as a so called comma separated values or CSV format file. This file that ends in ipynb is the notebook itself that you're just looking at. And then in this file called Utils Python. We've put some of the code you'll be using in this notebook, but you don't need to worry about what's in the code here. I just wanted to show you because it's a functionality that we put behind the scenes, so it's not to clutter up your actual notebook. Now I can click on the jupyter icon and then this notebook file to go back to the notebook environment. The way these notebooks work is that you need to start at the top and run each of the code cells sequentially. Each of the subsequent code cells will be able to build on the actions you took in the previous cells. So if you're familiar with programming, but not notebooks, you can think of this as a step function pausing through your application rather than it running all in one go. The way to run a code cell is to first select that cell and then press the run button here at the top. You can also press the shift and enter keys together as a keyboard shortcut to run the code cell. So I'll go ahead and run this first code cell at the top of the notebook. And what this cell is doing now, it's just importing a bunch of Python packages that we'll need for this lab. And this is a common first step when running Python programs in a jupyter notebook. The first step is importing the various packages that you'll need. And you can see we're also importing that utils file that you saw just a minute ago. And to be able to use the functions in that file as well. Like I said, that code could have been in this notebook, but it's not something we're looking at or changing here. So it's just for convenience that we've put it into a different file. As I scroll down, you can see that the next thing we're doing is to read the data again. And so again I'm going to run this cell by selecting it and hitting the run button. And this might take a few seconds to run. Okay, and now you can see it has printed some output. And so what this code is doing is with this first line, I'm reading in that same file the CSV file that we were looking at in a spreadsheet in the last video, after we've read in the data file, we're doing some modifications to the data that we're importing so that we can more easily use it. So here we're just converting the date time in that CSV file into a date time that's more easy for us to manipulate within the code. And you can see as well that we're pre labeling the different PM values. And because we're teaching this course in English, we're auto translating from ozono to ozone. And now with this next line, we're printing out the first five lines of the data set, which is just an easy way to see that the data was read successfully. Now, it's possible that while clicking around in here and running the code, you inadvertently introduce a typo into the code, like even something as simple as adding an additional space, which is something that Python is very sensitive to. Then when you try to run this cell, you'll get an error like this. When Python throws an error like this, it'll try to give you an idea of what went wrong in this case. In this case, correctly saying it's a indentation error. That's what the additional space has done. But if you're not familiar with Python, these error messages might look a little bit confusing. So if you do see an error at some point, don't worry, that's totally fine. And it probably just means that there's a typo somewhere in the code cell. You can try to figure out why the error is occurring and correct it. Or if you can't figure it out and get stuck, you can just reset the lab and start over. To reset the lab, you do that by going up here to the Help menu and choose get latest version. That will return you to the last fresh version of the lab. If there was in fact a new version of the Lab, you'd be able to update to that new version here. But you can also just use this functionality to refresh your lab and get a new fresh copy. That should allow you to clear any errors they might have introduced while editing the code.
Like I said before, I won't be asking you to write any code from scratch, but in some cases I'll be suggesting changing a parameter or two in order to see the some different output. So I don't want you to think about editing the code as completely off limits. Just keep in mind that you might get an error if you have a typo. And that's about all you need to know about Python and Jupiter notebooks to.
Be successful in these courses.
In the next video, I'll step through the rest of this lab, where you'll get to explore the data to get.
A clearer sense of what you're working with.










