Learn Data Science with Python - Part 2: Analyze, visualize & present data | Tony Staunton | Skillshare

Learn Data Science with Python - Part 2: Analyze, visualize & present data

Tony Staunton, Reading, writing and teaching.

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
10 Lessons (1h 19m)
    • 1. Class Introduction

      1:27
    • 2. How to get the most from this class: Skillshare 101

      1:39
    • 3. Class Frequently Asked Questions

      0:54
    • 4. How to set-up your development environment

      5:08
    • 5. Jupyter Notebook 101

      4:27
    • 6. Create Graphs, Plots and Histograms

      19:17
    • 7. Python Dictionaries

      8:23
    • 8. Python Pandas & DataFrames

      10:14
    • 9. Controlling the flow of your programs

      16:02
    • 10. Python Loops

      11:12
14 students are watching this class

About This Class

In Learn Data Science with Python - Part 1: Introduction to Python you took the first step on your journey to becoming a data scientist. 

Part 2: Plots, Graphs, Dictionaries, Control Flow & Loops, is an essential step to keep moving forward. Right out of the gate you will learn Python visualizations skills that you can apply in the real world. You will learn how to master Matplotlib to produce several plots and graphs including this amazing graph:

45e1d5f0

In lesson 2 you will learn how to create Python dictionaries which are like lists on steroids and will help you harness and manipulate massive amounts of data.

Next, you will be introduced to one of my favorite Python topics, the Pandas DataFrame which is the standard way of working with tabular data in Python. In this lesson, you will learn how to import CSV files so that you can manipulate and access the information within.

Have you ever wondered how computer programs make decisions? Well in lessons 4 & 5 you are going to find out. Boolean logic is the foundation of giving your programs the power of decision making. You will learn how to combine different comparison operators with Boolean logic to control the flow of your Python programs.

Each lesson in this class is created using Jupyter Notebooks which means that you can download the Python code, experiment and improve upon. You also get to keep the class notes for future learning and reference.

At the end, of the lesson is a final project to apply what you've learned.

After completing this class you will have the basic techniques used by real-world industry data scientists. These are topics any successful technologist absolutely needs to know. 

What are you waiting for? Enroll now and take the next step!

Transcripts

1. Class Introduction : Hi, everybody. Welcome to this class learned data science with Biden part to introducing you to plots, graphs, dictionaries, control flows and loops, which are all an essential step to keep moving forward on your journey to becoming a data scientist in this class, right out of the gate, you will land piping visualization skills that you can apply in the real world. You will learn have the master Matt plump lipped to produce several plots and graft, including this amazing graph right here and lesson to you. Atlanta Create piping dictionaries, which are like lists on steroids on, will help you harness and manipulate massive amounts of data. Next, you'll be introduced to one of my favorite topics, the Pandas data frame, which is a standard way of working with tabular data and pie eaten. In this lesson, you learn have to import CSP files so you can manipulate and access the information within . In the next lesson, you will learn how computer programs make decisions. Boolean logic is the foundation of giving your programs the power of decision making. You will learn how to combine different comparison operators with Boolean logic to control the flow of your programs each lesson. This class is creative using Cooper notebooks, which means you can download the piping cold from my kid Hope Age, experiment with it and improve upon it if you can. You also get to keep the class notes for future learning and reference. At the end of this class is a final project where you can try and apply what you've learned . After completing this class, you will have the basic techniques used by real world industry data scientist thes air topics. Any successful technologists absolutely needs to know. So what are you waiting for and roll now and take the next step? 2. How to get the most from this class: Skillshare 101: Hi, everyone. Now, in this short video, I'm gonna show you how to make the most out of this skill share class on have to enjoy our journey together, learning data, science with fightin. So as you can see, I have a draft of my course open here, and you can see my classes on the right hand side, there are more to come. But looking here now, focusing in on the video player window you can see on the left hand side the bottom lower, left hand side speed button so you can increase the speed. If you find Trudy Trudy classes I'm speaking to slowly so you can go all the way up to double a speed. You can wind it back by 15 seconds. If you want to relearn something or re listen to something over on the right hand side, you can view the notes, so that's an important part of people Sometimes. Miss, I often add notes to certain classes if people have feedback or questions, or something might have changed in the technology between myself teaching this class and you taking this class and then on the right hand side, you can switch it into full screen. And don't forget you can always higher and lower the volume. Suit your own needs. If we just scroll down a little bit, you'll see reviews community projects and resource is so in. The community section is the best place to go and ask for help should you need it in the projects. And resource is tab is where I add in the class project. Any resource is of files that you might need to have your learning journey up the top. You'll see the follow button, and they encourage you to follow me because I often release updates to my students, such as new competitions, new projects, new challenges, updates to the course on much more. I have a very active instagram feed as well. So check that out to stay up to date on the course on new piping, data science techniques and everything related to piping on this course. Now, finally, if you've taken and enjoy this class, please do leave me review with some feedback on what you liked or what you'd like to see improved about the class. That's it for this short video. Thanks for listening, and I'll see you in the next class 3. Class Frequently Asked Questions: Hi, everyone In this short video, I just want to show you where to go to get some additional help with the class on with uber notebook. So if you head over to get hope dot com for its last T Staunton, that's my get home page on my profile. See a number of repositories click on Learning data Signs were fightin. Then click on Part one. Introduction to Fightin and you'll see here Class F A. Q. So click into that and let's just have a brief look what kind of FAA cues we have. So do I need to have super notebooks and Anaconda installed? I'm not gonna go through each of these. I'm gonna let you read these at your own pace. Where do we get the resource for this class? Well, that's on. Get hope. How do I know where my notebooks are being saved and so on? And the last question is particularly useful. How do I get help if I'm stuck on something? So again, just a short video to let you know that I do have an f A Q page, and I add that all the time with common questions that come from students such as yourself to go to get hope and check that out. If you have any problems or don't forget, you can always drop me a message in the community section off the class. Thanks for listening. I'll see you in the next class. 4. How to set-up your development environment: Hi, everybody. And welcome to this class in this class. We're to go. We're going to discuss the environment set up. So exactly what those air a development environment looked like for coding pipe. So this classes tree main objectives that is to install piping would under conduct on, um on the home page here that you can see next downloaded zip files of all the class super notebooks and finally open and explore our Jupiter notebooks. For those of you who may not know what Anaconda is, it is a distribution of piping which includes not only piping but many libraries that will be used to wrote the upcoming classes. Anaconda is an all in one installed that is used depopulate data signs on machine learning . When you download and install Anaconda, the Jupiter notebook development environment is also installed. As I mentioned in the introduction, Jupiter is a development environment where you can write cold display images and make notes . When it comes to data science and machine learning. It is the most popular I d for exploring and analysing data. Before we go, any foreigner I'd like to point out that of you are an experienced piping user already have a development environment set up that you were happy with. Please feel free to continue using your set up. You do not have to use Anaconda or Jupiter to be able to follow along with the classes to come. The piping code that we're going to use can be used in any I. D. So here we are on the Anaconda home page and you can find it out anaconda dot com Now the Anaconda home page may look different when you come to visit due to updates and things like that. The main thing that we're interested in is the download button in the top right hand corner kick on that. Now you get a bit of its summary of what Anaconda is on. If you scroll down, you see a couple of options. So the first big one that jumps out at you is that Anaconda is available for piping tree and piping to We're interesting piping tree. Keep in mind that when it comes to this page, diversion number may have changed instead of 3.7 and might be treat 0.8 or 3.9. But that's OK. Piping tree is what this course is all about Before you select your pipe inversion, make sure that you are downloading for your correct operating system. So, as you can see here you have windows. You have Mac OS, which I'm aren't. You have. Lennox, if you were wondering whether you should download the graphic installer are the command line installer. The graphic installer can be a lot simpler to run on install as it runs. It gives you help. A helpful step by step guide. Truly installation process. She can see here Graphical installer. So click on that to download it for your operating system. Once the download is finished, go ahead and open up the file. If you're on a Windows machine, it will be a dot exit. Or if you're on a Mac, it will be a DMG ID away. Select your file now the Mac installers pretty seamless. But if you're on a Windows install, you need to pay attention to some screens that pop up in particular this screen here. So as I don't have a Windows machine, I've taken a screenshot of the insulation prompt. So on windows. When you get to this screen, advanced installation options, the forest box here will be on ticked. Make sure you select it even though it says not recommended. The reason it says not not recommended is because if you have already installed evasion of piping, checking this box will make Anaconda your d felt version of piping. But again, that's OK. Make sure you check this box before we proceed, then continue with the remainder of the installation. Now, when the installation is complete on a Mac, you will see Anaconda Navigator added to your list of applications. So I have a look in my application list. Here. There we go. Top right hand side Anaconda Navigator didn't windows in the lower left hand side. Besides start button. If you run Syria for Anaconda, you will see the anaconda options pop up. If I click on Anaconda Navigator, give it a moment for the interface toe. Open up. Okay, so here we are in an Anaconda Navigator home page. This is how you can lunch your Jupiter notebook on many other applications that comedy Anaconda Navigator on whether you're on a Mac or a Windows machine, this interface is going to be the same. This is essentially as I just said how you will access your development environment. What you need to do next is select lunch on the Jupiter notebook, and you should see a browser window open up with your computer files in the directory. Something like this. When you have Jupiter open running, just a word of advice. Make sure that you have a modern Web browser selected as your default Web browser. Something like Internet Explorer is not gonna work very well with Jupiter. You're better off using Chrome Edge Safari or Firefox something. Mother. Another thing to point out here is that when you're using Dupin notebooks, even though we're inside the Web browser, we're not actually connected to the Internet. Jupiter's just using your Web browser as an interface. Now we have Jupiter notebooks installed on pipe and hopefully, successfully. If you've any problems, let me know in the community section. Let's head on over to get hope and see how we can download all the class files that you are going to need now here, here on my get home page, And that's at get hope dot com ford slash t stardom and once again select a repository that you're interested in which is learnt data science with fightin where you can do here on the screen is clone or download the files. What you want to do is you want to download them, so download the zip file. Okay, so once your file downloads, you'll need to unzip it. So, on Mac, that sometimes happens automatically or on Windows. You'll need to use your default on zip file utility. So here we have learned land data signs with titans. That's a massive file on, as you can see, what in that we have part one introduction to heighten and all the classes that come with it. Let's jump back into Jupiter. As I said, here it is. Here would in my downloads folder you might need to browse to this folder in your Jupiter Explorer. Now, if you don't want to work into downloads folder safety on zip file to a location where you do want to work from. So if I click here introduction of fightin, there we go. All my Jupiter files ready to be opened on explored, and that's exactly what we're going to do in the next class. Thanks for listening, and I'll see you there 5. Jupyter Notebook 101: Hi, guys. Welcome back now. In the last class, we looked at installing an opening up Jupiter notebooks. We also downloaded the class files that you're gonna need going forward to kick this class off. I'm going to show you an alternative way to open up Cooper notebooks, which is from the command or the terminal window, depending on your operating system. So let's do that right now. So as you see here, I have my terminal window open on. I simply type in Jupiter notebooks. There we go. Give that a moment on. What that's going to do is open up a browser window with your file directory. Something similar should happen on your system. So as you can see, my default Web browser opens up with my computers file directory. I never gave in here toe where my notebook file they're saved on. Then I click on the one I want open. And here we are. If you have already downloaded Dupin notebook that we did in the previous class, you will have the exact same source code that I have in front of me Now. Now, in this class, I'm going to give you a brief very high level overview of Jupiter on its interface. So here we are, in a file structure with the all the files that we downloaded relevant to this class. But over here on the right hand side, you can see new we click on new weaken selector environment. So piping tree you might have several environment. If you have previous versions of piping installed on that's okay, select the one that you were working with or the most up to date one. So select piping training. In my case, on I get a new cell. First thing you should do is retired to yourself. So I'm just gonna call this example. There we go. Perfect rename. As you can see here we have a salad bar on This allows us to enter in piping code or just general Smackdown text. And look at that in a moment. But in the cell, if I typed print brackets quotation marks Hello. Hello. World is not how the old start Hello world You can see here This is a complete pipe and print statement. I click shifted, enter and I get the output Hallow world. I could have done just the exact same Think without the print statement by saying Hello, World again shifting. Enter and we get our output truck. This class, you'll see me used to print statement to generate output. There will be times when I don't use it. The output is the same with one difference here in that line. One. When I use the print statement, I don't get to the left hand side and out statement or an out market within line number. But as you can see down here in line to into, out to, that's the main difference. So I use it interchangeably throughout the classes. So have you seen the using print and not using print? Don't worry. You can wrap it all in the print statement or without the print statement, whichever makes you feel better. If you would like to add additional cells, you can do so with the following matters. So as you can see here, my cell is active and you know it's active because it's surrounded by a green box on the courses inside. If you press escape, it turns blue. This means that the sale is not active. We can do here now, a select A, which inside of two Sal above or select B, which insert to sell below. If you're working in a cell, so print hello, You can also insert a new cell below by instead of pressing, shift and enter to run yourself, press off and enter there we go automatically into a new cell. Now, at least out of the beginning, you can also add normal text into your Jupiter file. So again, press escape to make sure our cell is not active. You condemn press M or up here the drop down. You can select code mark down or whatever else you want to use. So I've selected M, so I click, escape and click Enter to reactivate that sell on. Now I can just type hello. Let's have a look at the output. Nowhere put because that's just normal text. So that's how you would add notes to your Jupiter file. So if you're writing a long or follow along with the classes, you want to make a note. You want to say I need to revisit this example. You could make a little note here for yourself. Or indeed, you'll see. As we go, you can produce massively big reports that tell us, Tell a story about the data that you are examining that you can use to print, save and export to share with other people and all sorts of way to export. And to do that, you just go up to the top parents. They file download as, and you can see all the options that you have here to export a Jupiter notebook. Some other things are important to know that if you're in Jupiter on your running your code away, sometimes you might want to restart. So up here you have Colonel, you can restart. You can just restart the entire notebook. You can restart in, clear the output and he can restart on ruin all the cells again. So that's restarting. Clear the output. So as you can see, all the output is gone except for the plain text. So again, I can click, shift and enter shift and enter on my output is there. That's just something to know if sometimes your programs get stuck or to taking too long to run. Now, if you would like to see the keyboard shortcuts for order options that you have in Jupiter , you can go help and keyboard shortcuts on here is an entire list off what you can do within Jupiter using the keys. I won't go through every one of these. I leave that to yourself. Okay. Thanks for listening. That's a brief introduction into Jupiter on. We'll be learning a lot more as we move to the classes. Thanks for listening. And I see you in the next class. 6. Create Graphs, Plots and Histograms: hi, everybody, and you're very welcome to this lesson. We're we'll be discussing Pie Eaton's Matt Plot Lib package on what's so special about this package. Well, it lets us create plots and graphs something very visual and something very very related to data signs. So let's get started. Data science is all about telling a story with whatever data it is that you were dealing with. It might be website visitor behavior or customer purchasing patterns. No matter what it is. Your jobs data scientist. It's used a data. You have to tell a story to understand and gain insights. Using visualizations is one of the most powerful ways that you can communicate your stories on insights. Matt plucked Lib is a pipe and plotting vibrate used to create visualizations. In this lesson, we're going to start by importing map lot lib, create some simple line scatter and history and plots on finish up. By creating this chart, I think you'll agree this is a pretty impressive chart, and if you're able to do this at the end of lesson, then you have come a very, very long way. So you might think this is outside your scope of them skill at the moment. But believe you, me, it's a lot simpler than you think on. We're going to step through it right now. If you would like some more information on my plot Lib, you can follow this link here on. If you would like some background information on this chart on its creator, I have added a Wikipedia link just here, so let's get started. So, as you can see here in this code bucks, I'm importing Matt the matte plot lib package with some package pie plot as plt. Now, we don't understand this line of code here in Port Matt plot lib dot p white plot As plt go back to class one of this Siri's where you will learn how to import piping packages. The next piece of code here is creating a new list. And again, if you're not familiar, a pipe list head back to part one. So the cradle list we simply defined a variable on the left hand side. Year 01 equals and then we have four years. 1950 1970 1990 2010. Next, we have a population list. So again creating a list we have a variable on the left hand side. On list are created with opening and closing square brackets. So we have world populations for 1950 1970 1990 2010. So you can see here populations increasing as the years increase. Now we're using Jupiter notebooks, which is obviously very clear. So shift and enter here, and that's our code cell executed. So far, we've simply imported my plot lib and created two new lists, noting new from what we have learned in previous lessons to plot this data as a line chart we call plt dot plot on. We use the to list as the Axis. So how do we go about that? Well, as you can see here, plt dot plot open brackets years here one comma pop 01 close brackets. So what we simply don't here is using the plot method we've added as arguments are two lists Year 01 and pop 01 Shift in and around that and there we go a very simple line chart . So a couple of important things to point out at this stage, the examples in this lessons are created using Cooper notebook when creating plots. There is usually a PLT Dutch show statement, which tells piping to render or show the actual plot on this is usually placed at the end of a program. Jupiter Notebook does not require the statement, but it will be required in order. Tax editors or i d. Ease the plot function Towns. Pardon what the plot on how to plot it show. Actually displace the plot. Take another look at the line plt dot plot and see if you notice anything out of place to take a look again at this line here. If you've taken part one of this learning Siri's, you might recognize something a little bit unusual in this line here. If you picked up on the semi colon well done, adding the semi colon here is a choice. I make the hide additional output that is produced when the plot is created, so go ahead and remove the semi colon. You'll see the difference. Let let me hear now remove the semi colon shifted. Enter on. As you can see, you get this line of output here, but it's unnecessary for what we're trying to do. So I just put back in the colon shift and enter on. There we go. So for the rest of this lesson, you're going to see the semi colon at the end of several lines of code on. Don't worry too much about it. Okay? So if you're able to follow along so far, you've just created your first plot. I'm well done. As you can clearly see, Piping has drawn a line between the data points off the lists. The list year 01 was used to create the X axis and was the first argument in PLT that plot our second list, pop 01 was used to create the Y axis. And what's the second argument in our plt dot plot? So what do I mean by the first and second arguments? We're back up here to this line of code. As you can see, Year one. First Argument pop. 01 2nd argument. Now we can quickly and very easily change a line plot into a scatter plot. We simply replace the word plot with scatter, so we take a look below. We'll see a scatter plot, which shows data point without them connecting by a line. This makes them easier to read for many applications. The scatter plot is sometimes better than a line plot. So let's have a look here. So as you can see here in this line of code, plt dot scatter and again, our first and second arguments are to list. If we shift in entering this here we go scatter plot. So instead of having a line connecting all our points, we simply have individual points. The two examples of both have Bean simple and created. Using two lists. Let's bite off something now a little more challenging but lower two lists gross domestic product per capita on life expectancy. I got these figures from the World Bank. Data sets, which are freely available for download on, have included the link here. In the later lessons, we will learn how to import data files directly into our programs. But for now, using list will suffice. Make sure to go to my kid Hope Age and copy the to list on. Don't try and type them in my hand because, as you can see, there's an awful lot of data here. I've done the hard work for you, so you just go on copy and paste. So our first list GDP, underscore Cup equals and then we have our gross domestic product per capita or listed here , shifting entered to make sure it's processed. Our next list is life expectancy. And again, don't bother typing. Descend, go to my get home page copy and paste it. Using what we've learned so far, let's plot these two lists. I'm gonna put GDP underscore Cup on the X axis on life expectancy on the Y axis. This means that the most take positions one and two, respectively, in the plot function. So let's have a look. So, as I just said, Position one GDP on a score cup on position to life underscore expectancy shifted. Enter. Oh, okay, that's a bit rough. The date is not very readable. And I really do think you have some sort of special genius to pull any insights from this chart. Let's keep going on making a scatter plot on again. To make it a scatter plot, we simply replace the word plot with scatter. Now, this actual line of code here means that on the X axes I've added in a lot rhythmic scale. Let me just shift on, enter on this and then I'll explain what a logarithmic scale is. Okay, that looks a bit better. That's pretty nice. So again, as I just said, you'll notice new line of code plt dot exe scale lug. Supplanting the X axis on a logarithmic scale helps us to view and understand large amount of data much more clearly, and I think you'll agree. If you look at this plot, it is much clearer. A logarithmic scale is a non linear scale and used for large range of positive multiples off some quantity. It's based on orders of magnitude rounded on the standard linear scale. So the value represented by each equidistant mark under scale. It's a value at the previous mark multiplied by a constant so we won't get into into the algorithm of this. But you can learn more here at this Wikipedia link. Okay, so now we're starting to look in better shape on even from this area check. We can start to glean some insights about our data. What we can see is that higher GDP seems to correspond to a higher life expectancy. So here we are here, so higher GDP, higher life expectancy. So, in other words, there is a positive correlation. So below I've created a new list called Population Tree or Pop zero Tree, which shows population data to go with our existing GDP on life expectancy data. Let's use a scatter plot now the plotters okay, not telling us too much here, but we can fix that with a hist aground. Let's talk about history Rams now, which are used to explore the distribution of data. What does that mean? Well, imagine 12 values between zero and six in the image below. I have placed him on a number line. So in this forest image here, you can see 12 values represented by the green dots. You can also see that along the line it's divided into equal chunks known as bins. So here we have been one. Been to been tree all the way up to Ben. Six on. We have our values. Inside each of these bins. Let's reorganize our number line into tree bends with a width of two each. So here we go. Go now in the second image on the pains of being reorganized with a width of two. And as you can see, we have data points represent represented by the green spots in each one. So how many data points sit in each been? And the first been for in the second Ben. Six. UN in deterrent Been, too. If we were to draw a bar in each, been the height off, the buyer would represent the number of data points in each been so, as you can see here, the height of the spire here is for the height of this buyer here. Six. On the height of this buyer here is to with a history Graham in place, we can now see how the values are distributed. Most values are in the middle, and there are more values below to than the Arab before. Now that we understand the basic hissed a grand, it's time to use Matt. Plot lived to start creating them as always. If we need some help, we can call help brackets plot plt that hissed. Let's take a look. Okay, so here's your help information. Scroll back up there and scroll down a little bit here to make it easier to read on the screen. So look at the forest to values safe for us to values. I'm pointing at this location here. X is the list of values you want to build a history Graham for on the second argument Towns Pipe and How Maney Bends, the data should be divided up into Based on this number. History will automatically find appropriate boundary for all bins and calculate how many values are in each one. If you don't specified Ben's argument, it will be 10 by default. Okay, so let's create a working example. Here we are in our code cell, and the first thing we're doing is importing Matt Plot lib. We're den creating a new list of values. So on the left hand side, we have our values variable. We're assigning that the list of several different values and how do we know about piping lists or part one of learning data signs were pardoned. Explains all this. If you want to take that class, head over to my profile page and you'll find it in their our next piece of code here called hissed. So where previously had plt dot plot or dot scatter? We now have dot hissed. We're giving it the values from our list, so we're taking the variable here. Values were adding it as the first argument in our history read and handing it to create tree bins. Okay, that shift in endurance and see what we get hissed a gram. Not too bad, but not too good idea. In our next example. Let's plot life expectancy using a history, and there it is. Okay, again, Not too bad, not to good. Let's do this again. But this time, let's specify the number of bins. So, as you can see here, bins equals five. Shift and enter. Still, not great. Let's drive Benz Eagles 20. Okay, much better. So too few bins will over simplify reality and won't show you the correct details. Too many bins would over complicate reality on won't show you the bigger picture. As you can see, we're getting Maurin sites with 20 bins, hissed a grams. Make it very easy to compare data. Let's do a comparison now. The list life underscore e x p contains life expectancy data for different countries in 2007. Below is a second list life underscore E X p 1950 which contains similar data for 1950. Let's now make a hist a gram containing boat lists. So again, here's my list life underscore E X p 1950 on again Don't air Type Wallace and head over to get hope on copy and paste it from there. Shift and enter and then within the one code cell, I'm plodding first hissed a gram. Life expectancy on giving it 15 bins on applauding the second list with a history. Graham Life expectancy, 1950 Again, Ben's equals 15. Let's shift in entering dot Okay, much better. As you can see here, we can now compare to hissed a grams in the one chart. Let's discuss now customizing plots. One of the biggest challenges when dealing with large data set is communicating your findings on allowing orders to gain insights from your visualization work again. What you're trying to do is to tell a story with your data to help with this challenge. Matt Pop Lib allows us to add customization to our plots, sort of the easier to read and understand. Let's take a look at an example the help demonstrate. So in this line of code, as always, we start off by importing our math plot led package. Next, we're creating a list of years. So year 04 equals on. We have a list of years from 1950 all the way up to 2015. So once again, don't bother typing this in. Simply copy and paste it from my get home account. Our next list. It's a corresponding world populations 40 years, and this list is called Pop 04 Now let's plot year 04 on the X axis on pop 04 under y Axis . And we do that. But very simply plt dot plot years. Therefore comma pop 04 enclosed in brackets shift and enter and there we go. So at first glance is not actually a bad looking plot, but if you're a study it a bit longer, what do you know? What data is trying to communicate? What story is it trying to tell? If I just handed you this plot with no context, would you know what it means? Probably not. Let's help this plot communicated story by adding labels to the X and y axis. And to do this, we used the ex Labour and why labor function so again the same code as the example. We've just gone through importing our package, creating our lists, plotting our lists down here. Now we have an extra line of code plt that X label on. We're giving the X label year next. Plt dot white label on. We're giving the white label population that shift and enter on that. Okay, much better, as you can see here on the left population. And as you can see here, down here on the right year again, same piece of code is both. But the last line here is different on what we're doing here is you can tell by the comment is adding a title. And we do that with plt. Got title open bracket quotation marks, world population estimates. Let me shift in, Ender. There we go. A nice title at the top of our chart. So at least now the reader knows what this plot is about. Now let's make the y axis start from zero for more context and we do this with the white takes function. So again, the code to this point is exactly what we just typed in a both. So I won't go through it for you. But the last line here as to common says stature y axis at zero. So what we mean by that? If we just scroll up, you can see our Y axis here is starting a tree. We wanted to start at zero, and we do that with the white ticks function on that. You can see we're starting here at zero. And we're going up to eight That shift and enter their perfect you go zero all the way up to eight. We can add a second argument to the white takes function, which will forge a annotate er access. What do I mean by that? Well, if you go down here, we have what? We just entered White IX 0 to 8, and they are enclosed in square brackets, followed by a comment on our second argument. As you can see here, we're adding strings so these strings would be attached to the ticks on a Y axis. Let's have a look what that looks like. Okay, So now, instead of just having simple 01234 Now we have one B two b representing 1,000,000,002 billion, three billion of world population. So again, further information further helping to communicate our story. Okay, doing some research on Wikipedia, I found some additional population data. Let's added to our current data set. Now, if you're unfamiliar, would have to do this and the code that is the calm below, or indeed the code that we have been working True, which regards the lists. Take a look at, As I have been saying at part one of this series, which covers fightin lists here we're creating two new lists Year 06 and pop 06 were assigning tree new piece of information to each one years on population information on. We're then adding them to the previous lists Year 05 and pop 05 on. We do that with the plus symbol. The same code is above that. Run it again on as you can see, the additional information that we've added here starting at 1800 going 18 50 1900 the population too much. So we now start our charter 1800 rather than if you just scroll up 1950. So we have successfully ADM or information to our chart. Now let's go back to the data were using at the start of this lesson, which waas GDP underscore Cup on life underscore e x p so to lists of world data shifting. Enter now. What are we going to do with this? Let's have a look. Letting New and his codes out just organized a little bit differently for us. We create our basic scatter plot using plot dot scatter and then we put in our lists as arguments. GDP on a Score Cup on life underscore e XP on again. We're gonna put this on a logarithmic scale. Next, we're going to create string variables to represent X and Y axis on the title label. So as you can see here, ex Labour, why label title variables on her left hand side on? I'm assigning to them the correct strings of what that access should be called in the next piece of code were adding her labels. So plus that X label and we sign it the variable X lab plot that Why label reassigning the variable? Why lab and finally Reata title shifted Enter and there we go. So the information that we had plotted previously, but with a little more explanation on the X and Y axes on a title we conf ordered customizes plot using the tick function that we learned earlier So here I'm defining the tick value on the tick lab. So tick value is 111,000 on a tick label is one K 10-K 100 k So now we put the ticks on the X axis. Plt dot ek sticks on we insert two arguments. Finally, we use plot dot show, shift and enter. There we go. So as you can see here we have our logarithmic scale. But now we have replaced that with Arctic values 111,000. Next, we have our population list, which we're calling pop 07 Shift in entering that in this code sell here, do a couple of new piece of information. We're creating a new empire A So are taking our list. Pop 07 I'm returning that into an umpire A and assigning it the variable n p underscore Pop . Next we're taking np underscore pop and we're multiplying by two to increase their values. And you'll see what I mean by that. In just a moment in the next line of code, you'll notice here that we have s equals np underscore Pop on what this is assigning np pop to a scaler. Okay, let's plot this and see what we get. You can see here now that we're starting to get size, represent representations by population. Obviously, here we have countries with very large populations. So you have to guess at the moment I would say China and India. And that's why in the example above we said MP times, too, it was just to call out the populations we don't assigned after the scaler, which is the shape. What we want to do now is we want to take these individual population spots, and we want to add some color to them. And we do that forced by creating a list of colors. Color equals on again copy paces from Get hope in her next code sell here. You'll notice there were starting to assign variables to her lists. GDP on a score cup. Why equals life on the score expectancy on? We have our scaler. We then assigned our color our colors to the argument See on Alfa, which is a blending value at 0.8, and you can experiment with that if it doesn't look the same when you plot this information and the next lines of code. There's nothing new here, so I just shift and enter and that you can see here now. Our colors have being transferred in now, as I mentioned previously, thes two large population dots on most likely Indian China because they're the most populous countries in the world. So what we can do is we you can add some annotation tour chart on here. We have plt dot text followed by tree arguments. The first out to arguments are points on the chart, so you'll have to experiment to get it just right on the set and the turret argument on each one art attacks we want to add in the next line of code plt Doctorate True tells our plot function that had agreed to our chart that shift and enter. Okay, that looks absolutely brilliant. As you can see, here are two big red dots. Are India and China very, very clearly called that were annotations. We've added a grid to make it a little bit more easier so that we can align it up with their GDP on our life expectancy. So we started this class knowing next to nothing about the matter plot lead package on how to create line plots, scatter plots and hissed a grams. We finished off by creating what can only be described as this beautiful chart. So for more information on this and other charts created by Professor Hans Rosling, you can google him or check out his wick Wikipedia page here. Thanks for listening on. I'll see you in the next lesson. 7. Python Dictionaries: Hi, everybody. And welcome back in this lesson, we're gonna be looking at heightens dictionaries, which are new data type. So previously we looked at Lists on dictionaries are similar to list, but on steroids, let's revisit our list of employees on departments. So here we have two lists, one called Team Areas on. Do you recall team members? So our team areas consist off developed design and finance. So department you would find within a business on a team members Tony, Mark and Fiona or done expressly looking at these lists and seeing that mark works in the design department. How can I run a query to pull this information? What would happen if I had a list of employees into thousands? How would I know what department and employee works in? Let's see how we can do this using lists. So here we're going to use Index to get the index of design. And once again, if your own familiar with any of the topics covered in this lesson or any of the lessons in this class, then you're in part to at the moment. So head over the part one which you can find on my profile page on That's part one of learning data science with Fightin, which covers piping basics such as list numb pies and things like that, and really will help your learning and understanding if you've already taken part one off this learning Siri's. So here we create a new variable called Index Underscore Design until that very a breed assigned the index off design. So, as we know from Part one are indexes started. Zero. So here we have 01 to the next thing we want to do is print out that variable, so print team members index. So from the team members list print of the index of design here we've built to list and then use Pipkins Index function to retrieve information. It works, but not very well. You can see how this would quickly become unmanageable with longer lists. Using piping dictionaries, we can link each department to its employees into code. Example below. I have used the information from T Mary's and team members to create a dictionary. Let's take a look it up now, So here's a dictionary here and, as you can see, dictionaries, a creative curly bracket. So we for us curate a variable called Project on the Score Web onto Not variable. We're going to assign a dictionary. So, as I say, dictionaries are created with curly brackets. Inside the curly brackets, we see a key, which is here. The first example. It's called Developer Enclosed within quotation Max. We next have a colon, followed by another string, which is called the Value. Again enclosed in quotation marks. This is known as the key value pairs, which link information together. In this example. Team areas are the keys and team members at the values. The first keys development and its corresponding value is Tony. Each key is separated from his value. As I've just said, we're colon on. Each key value pair is separated from one another with a comma. When we have finished creating a dictionary, we consign it to a variable. On this example, it's called Project Underscore Web shifting under. Okay, so now that we create a new dictionary, we can call the value for an ME department with the following coat and we just scroll down here a little bit. So Project Web, which the name for a dictionary and we want the value for developer, which is a key. So that shift and enter here. Okay. So, developer Tony, what we've done is we've called Project Underscore Webb, which, as we know, was a dictionary. We've done you square brackets to insert a key on. When we output the key, we get the value. Let's try another one. So here we have project Underscore Web. Okay. Again. So our dictionary name square brackets on design that see, Mark. Okay. That's just insert a new line here on Let's run it again. So project underscore web. And if you want auto, complete your variable names all you have to do indistinct like I just did. There is type in a couple letters on the top key. So project Web square brackets, quotation marks on let's do finance. Not jiggy with an F shift in Enter Fiona. Okay, so we put in the key to get the value out. If you want to recall the entire dictionary, weaken, simply type print brackets. Project web. So what we're doing is out putting the entire dictionary. Let's take a look. There we go. As you can see, we have the key value pairs from all the dictionary. If we only want to help put the keys. We say Print project underscore web dot keys brackets And there we go. Just a dictionary keys on. If we only want to print out the key finance, we say Print project on a score. Web brackets finance Fiona. There we go. So I'm creating a new dictionary. The keys have to be. The unique keys are mutual objects, which means that the contents cannot change after they have been created. Let's see how we can add another key value. Pair toe a project Web dictionary. And, as you can tell, here I have that backwards or just changed up in the moment while I remember it. So project underscore web. There we go. Okay, let's add marketing on the name of the Paris we want to add is Jane. So to do that, we call out a dictionary project, underscore Web. We then insert the new department that we want to add, so square brackets, quotation marks. Marketing equals Jane. Next line Ever put Project underscore Web. Let's see what we get on. There we go the last key value pair in the dictionary, marketing and Jane as the value. We can also check if marketing has been successfully added using the following line of code marketing in Project Web. And that's true because, as we know it's in there now, with same syntax is before you can also change values. The code example below updates the value and developers from Tony the Amy. So how do we do that, we say are dictionary name, square brackets, quotation marks and the key off the value that we want to change. So as we know developers, a key equals Amy. So we're assigning to value Amy to the key developer. That's output. This there we go. Developer now is no longer Tony. It's Amy. Pretty simple stuff because each key in a dictionary is unique. Piped knows that you're not trying to create a new pair but updating an existing one. And how do we remove a key value pair from a dictionary or we do this with the delete function? So here we have delete Project on the Score Web. What key value pairs we want remove. We want removed developer. So we have square brackets on. We add in Developer. Let's put that now by simply typing in project underscore Web on as you can see we no longer have a development department on a member of staff attached to that department. As you've probably noticed. By now, dictionaries and list are very similar. They both use square brackets. A select update on remove values. A list is indexed by arrange numbers. A dictionary is indexed by unique keys so you can use the list when you want a collection of values. When order matters and when you want to create and select entire subsets, you can use dictionaries when you need a look up table were unique keys and speed matters, so dictionaries are much quicker and using lists in the previous lesson we've seen that list could contain anything even order lists on. It's the same for dictionaries. Dictionaries contain key value pairs where the values can themselves be order dictionaries . So let's look at an example here again. We're creating a new dictionary Web on the score Project zero to on our first key, his developers. On what? In there, we have a new dictionary, lead developer, so key value pair, lead developer, junior developer closed at dictionary. Next, we have the key design and the value for the key is another dictionary again, created with open and closing curly brackets. Finally, we have another key finance on in finance. We have another dictionary and we have to staff related to that department. How do we access the values of a dictionary within a dictionary? It's pretty simple. What we do is we print out our dictionary name, so print open brackets Web underscore Project zero to the first thing we do is add into the name of the key. We want access, which in this case is designed next doing the same thing again. We add in the key, we want access. So we want to know who the head of design is within the design department when we get that era, because I didn't shift and enter here and there we go. So we're in the design department. The head of design is Mark. Okay, Lets no create a sub dictionary on. We can do that by creating a new variable called temp. On the score team on. We signed out a new set of value key pairs head of marketing Jane on researcher Harry. Okay, so Attempt Team dictionary has been created. Let's now add the temp team to our Web project under the key marketing. And how did we do that? Well, again, the first thing we type in is our is our dictionary name. Wind, in this case is Web Underscore. Project zero to we open and close square brackets on. We add in the key marketing to that key we don't assign tempting. That's once more print out our Web project. And there we go Last line. Here we have a new key value pair with the values being a dictionary. Not too bad, not too complicated. But it can take a bit of practice to get used to dictionaries, particularly when you're assigning dictionaries would in dictionaries. So that's it for this lesson. But don't forget, if you any questions or problems, you can contact me and other students in the online community forums and Q and A 8. Python Pandas & DataFrames: Hi, everybody. And welcome to this class where we're going to be exploring piping pandas, which is one of my favorite topics and piping, and you'll see why now in a few minutes, because they are incredibly powerful in your data signs career. Most of the data that you will interact with will come to you in tabular form and usually in spreadsheets or CS three files with tabular data. Think of columns as variables and Rosa's observations. Let's take a look at an example. I mean scroll appears or a little bit easier to read, So the first thing I do is create a list of Random World countries. So here I have my variable countries and to that openings close square brackets on some random world countries. In their next I've created a new list on, but in this list you can see here it's called Speak English. I've assigned true or false related to each country above, whether or not they speak English as a first language. And then finally, I've created a turret list called Pop Underscore 2015. So in 2015 what the population waas of each of the correspondent countries, the first thing you need to do when working with pandas is to make sure that you have to package installed. So if you don't go ahead and do that now using Pip now, I've mentioned this before, but it will really help with your learning, particularly new deep Iten if you watch Class one off this learning serious on this syriza called Larrin data signs with Fightin on were in part two of that series. But there is a part one. So if you haven't already jumped back and watch Part one, if you're not familiar with Pip and have the ad packages to your pipe installation with that away, what do we do next? First thing we do is import pandas as PD. Next, we create a new dictionary. We're tree key value pairs from the list above. So we're calling this Dictionary World Dictionary onto that. We're assigning the key value pairs country speaks English on the population. Next, we're going to use this dictionary to create a data frame, and we do that with the PD dot data frame function. So let's call this data frame world countries on. Let's assign it pd dot data frame world on the score Dictionary. Let's take the dictionary from the previous line and convert that into a day to frame with the variable world countries. Let's print that world countries. Now There we go. Country speaks English 2015 population. So as you can see, what we've done here is taken our list. Put our list into a dictionary and converted duck dictionary into a data frame, which is essentially tabular data format. In this output notice how are rolled Labels are automatically set the integers. This is not necessarily a problem, but we can clean it up. We can create a new, very book called Roll Labels On Here Is that variable? Now Row underscore labels equals, and as you can see, I've imported the short name of each of the country's. Next we add this new variable to the previous code. So here we go and this is the previous cold. Just all in would coat born codes out in case you think it's any bigger or different from what we just don't we're starting off import pandas PD. We have our country's list are speaks English list on a population list. We don't create new dictionary using as the values the list from above. So as you can see here, we have two key country on the values assigned to that is the list countries and so on speak English and so on population again, we build the data frame. Now we insert the line, which will create the new index in this line of code. As you can see, here we have our country short codes created as a list on to done list. We assign it to the variable role labels. Next we use to index medic to assign role labels to the data frame. So how do we do that? We're calling this day to frame world on the score countries. So let's chain on dot index and that index is going to use the values contained within the list. Row underscore labels that's print that out. Bank. There we go. Look at absolutely beautiful. So we have our country short codes. Here is our index and then over here we have the values in tabular format. So far, we've used list to create dictionaries on dictionaries to create pandas data frames. However, we can also load CSP files directly into a data frame with the pd dot reid underscore CSP function on Here's how it works. So we're going to create a new data frame from import data with data I'm using is available from my get home page in the folder called Data Sets. So the Creator data frame we're just gonna create new very with DF, which oversees times for data frame onto dot We're going to sign it. The CSB file speaks English, and how do we do that? We used to read Underscore CS Function. Pedido read underscore See SV on as an argument, we pass in the location of our CSB file so, as you can see it in a folder called Data Sets for its last name in a file that's print out our data frame. As you can see, there's one small problem with the cold output. We have two indexes the index from a data file and the one automatically assigned by pandas . To correct this, we passed the parameter in next underscore called equal zero toe r P d Don't read on the score. See SV, Let's have a look at how we would do that. So, as you can see, here was just out of them. One new argument to PD read on the score. See SV! And that argument is index underscore. Call equals zero. Let me shift and enter again on this, and there we go indexes cleaned up nice and clean. The former. Now that we know how to create data frames, it's time to learn how to select specific information from within them. We can do this using square brackets, of which there are several ways to select specific information from a data frame. And they include location based selection. Indeed, your location based election on selecting specific columns in the example to follow. Let's explore each one. So the first thing we're going to do is select a specific column from the data frame on How do we do that? The first thing we type out or enter in whatever way you want to phrase it is the name for data frame open and close of square brackets and type in the name of the column. We want access. In this example. We want access the country column, that shift and enter. As you can see our country columnist output it along with the index. What does the last line d type object mean if we check the type of DF country, the Oprah tells us that we're dealing with a panda Siri's, which is really just a labelled one dimensional array on. Let's just confirm that now, using the type function, there we go. Pandas dark core dot Siri's If you want to select the country column, but keep it as a day to frame, we use double square brackets instead of single square brackets. Let's take a look at what that would look like. Me just scroll up here to make it center on the screen. As you can see here now, our output is a day to frame on. The nice thing about a data frame is that it appears in a formatted, tabular way. Let's check the type of country and, as you can see here, rather than being a syriza's the example above. Now it's a day to frame. So how about selecting more than one column staying within double square brackets? We simply add another column separated by a comma. Very simple. So here we have to name for data frame DF two opening square brackets on the names of the two columns that we want to access country on 2015 population. Let's print that out and there we go. Nice, clean, formatted data frame. We can also use the same square bracket notation to select rose from a data frame. We do this by specifying a slice that's called out the EU countries from our list. How do we do that? Slicing involves a colon, so DF zero colon four. And what does that give us? That gives us the roads that are within the EU, Ireland, the United Kingdom, Germany and France? As a previous examples of slicing, the index started zero on the end of the slices not included. The functionality of square brackets is limited, ideally what we would like. It's something similar to to Dean Umpire A's, which is my underscore array. Row and column patterns can do something similar with the Loken. I look functions so Lok allows you to select based on labels. On I Look allows you to select based on integers. Let's look at an example. Let's examine our data frame. So here's a data frame. How can we select the role of Ireland, which is where I'm from? We put the label of the role we need in square brackets after look. So we have DF dark cloak. So we're changing Lok to our data frame. Square brackets, i e. So we want to select this row here, So let's see what I put this gives us. There we go Country Ireland speaks English. True, which is true on the population of Ireland in 2015 was 4.7 million. What is returned to us is a panda Siri's containing all the row information. But as you can see the Roe information, this is based on separate lines. To return a day to frame, we have to put a roll label inside another set of square brackets like previous examples. There we go, nice and clean, which has selected the IE Row on. I'll put it that now we can also select multiple roles at the same time. To do this, we simply after the role list, whereas previously we had the IE label. In this example, we've added U K and D E for Germany. There you go, tree rose, nicely formatted output. It obviously this outputs the full role of data on We can extend our selection with a comma and specify the columns of interest. So here we have DF dot lok to opening square brackets, the roads that were interested in so the labels or the index of the roads that we're interested in. And now we can specify the columns, so we want to take the country columns on the 2015 Population Column on We want to leave out, Obviously speak English column Let's see what we get. Okay, there we go. Very similar to the example above except to speak English Column is missing. We can also use Lok to select all Rose on. Also select only columns of interest simply replaced the first list that specifies the role able to put a colon, which, as we know, is a slice going from beginning to end. So here we go D f dot lok open square brackets colon. So we're slicing everything, followed by opening square brackets again on the two columns of interest. What does that look like? All rose on the two into two columns that we're interested in all rows and two columns that we're interested in this time being Country on 2015 population square brackets work for columns to get roles Were you slicing? Lok is much more versatile. We can have row access column access are rolling column access using lochs upsetting a similar to sub setting to Dean Umpire A's, which we saw in part one on. We have to use role labels, not element positions. I look, on the other hand, allows us to subset panda data frames based on position. We've just seen have to access the single or multiple rows with Roe label with I Look, we used the index So what are we going to get here DF dot I lok double square brackets zero . What do you think the airport of that is gonna be? Well, as we know, indexing started zero. So hopefully they should be the Ireland Row. Perfect. We want to select more than one row. We can just add in zero comma, one comma, two cometary. Let's see what that gives us. Hopefully the 1st 4 rows. Yep. Perfect. If we want to use I look to select rows and columns. We add the column positions using I look to select the 1st 3 countries with their country name on population would be so Here we have the name for data frame change. Would I look and what we're doing? Forest is selecting the rose 01 and two and then selecting the columns. So the columns 02 Let's see what that gives us. There we go Country on 2015 population select All rose Together with the country in population, we would write the after I look opening square brackets colon comma, opening square brackets zero comma to enclose a square brackets Why do you think that will give us exactly what you think All rose as denoted by the colon on the two columns that we're interested in? Zero and two. So we're skipping over to speaks English column. OK, that's it for pandas on. Like I said, this is just a brief introduction to the pandas topic. We have a class which will come later on in this learning Siri's, which will go into much more detail in Panda's. Thanks for listening. And I see you in the next class 9. Controlling the flow of your programs: hi, everybody, and you're very welcome to this lecture where we're going to be looking at piping logic, control, flow and filtering. Let's kick off In the previous lesson, we worked with numb pie and the pie tin type. Pulling in this lesson, we're going to explore comparison operators, which are used to show how piping values relate. For example, to is greater than one. True, one of the most common uses of comparison operators is the comparing numbers, just as we did in the example above. Another comparison operator is a double equal sign, which is used to check if two values are equal. So here, in this line of code, we have turned the eight double equal sign. 32 is 38 equal to 32. That's hope. This, says faults. Okay, faults when needed. You can also combine operators. We can combine the greater down operator with the equals operator. Let's have a look at what that would look like here we're checking if 32 is greater than or equal to 38 let's hope began to says Faults 32 is greater than equal. 38 is false. This example is Turkey to less than or equal attorney, too. And that says True. If we have two variables that represent integers, we can use thes would comparison operators. So here we've created X equals four and why equals two? So is X less than why Faults cause Excess Forum wise to let's have a look that's just turned us around is X graded and why. True, let's look at string comparisons. You might not think it, but comparison operators can also work with strings. Here we have Albert is less down part. So what does that mean? It's true. So if you know your A B C's, you know that a comes before B, so the result of the both comparison is true. So far we've looked at integer and string comparisons, but we cannot compare warn with theater, give it a try and see what happens. The only exception is floats and integers. So here we have Tony, which is a string, is less than 40. So what happens if we tried up? We get an error and the error is pretty clear. It's telling us that the less than operator is not supported between instances of string on integers, but now we have afloat on an integer. So 38 is greater than 37.5, which is true now. In part one of this learning Siri's. We looked at Peyton's numb pie raise. Let's revisit the example that we use from Part one, which is using salaries within Umpire A's. So again, what we have here important umpire. As MP, we create a new list of salaries. So Salaries 2019 equals opening closing square brackets to create a list. And then we have salaries in their separated by commas. Next we create the very about new salaries on to that variable. We assign it an umpire. A. When we do that with MP dot array, giving it the argument salaries 2019. So giving it the list. Now let's use the greater down to find old salaries above 25,000. So big salaries equals new salaries, which is an umpire, a greater down 35,000 and print out big salaries. So, as you can see, it's a building returned, false or true, behind the scenes. How does numb Pint know what to do when numb Pine knows that you want to compare every element in the array new salaries toe above 35,000. It also knows to return a building faults if the element is 35,000 or below, and true if an element is above 35,000. To do this, numb pie creates a temperature. Rey filled with 35,000 and then performs an element by element comparison. Sounds simple enough when you think about, Here's a table of common comparison operators. Now let's look at equality. So as I mentioned at the start of this lesson, equality is to equal symbols. It can be used to check if two values are equal. So here in this line of code check of 38 is the same 38. True is true to Samos. Faults, faults. We can even compare strings so Tony would've. Why is that? The same is Toni with an I? It's faults on. We can compare Bowling. So true is the same as one true perfect. Let's look at how we can compare a raise, as we've seen in an example above, we can we can use comparison operators with no Umpire A's. Let's look at another example so again, here we have important umpires MP. So what is this here? This is weekly sales for a particular store store. Underscore one underscore sales we're creating that variable equals 12 1,401,900. Now let's take those sales and convert them into a numb pyre. A. And we do not. With the same method as above, we create the variable on the left, and to that variable we assign a numb pyre. A. We use NP daughter, a function on within the function. We pass in one argument store one sales. We do the exact same thing now again, this line of code here, except that we're using a second store. So what did a weekly sales for store number two? So now we have to know Umpire A's created. Our average sales are 1300 per week. That's print out. If Store one sales are graded on average, sales on also print out a store to sales are greater than average sales in the first week. Both store sales are less than the average in the second week to true Turd week did not true on in the fourth week one his faults on one is true. Let's print out our store. One sales greater than store to sales, as you can see here now, on a week by week basis. True, false, false, false. So in only one week where Store one sales great and store two cents Boolean operators a keyword searches and or not we can use these keywords combined billions and produce result . Let's take a look. We'll start with the and keyword on Takes two Boolean values on returns True only if voter true. So what does that mean? What we have true and true, which is true, false and true is false. Because both values have to be true. True and false is false, False and false is false. Let's take a look about using a variable X X equals 38. True and true equals. True, so exit destined for 40 on X is great and 25. It's true because X is less than 40 and X is great and 35 X is 38. The or keyword requires only one of the Bolin's it uses to be true. So true or true, true, false or true, True, true or false? True photo faults faults because not one of them is true. And just like the and operator. We can combine variables. So here we have X equals 21. Let's use that now to see X less than 18 is false on X. Greater than 18 is true. So how'd we do that? There we go. Excess in 18 or ex graded on 18. It's true, because one of those comparison operators has equal to true now did not keyword simply negates the building value were using. So here we have not True is false and not false is true. You were typically used in, not Operator, to combine different Boolean operations and then want to negate that result. How can we used in these new Boolean operators within Umpire A's? Well, let's go back to our store sales example here we're creating a tour. It store on again. We're adding in some weekly sales were converting those weekly sales into a new empire. A. Now, within the store, let's find any sales at a greater down 600. The opening, once again, is an array off billions. Now, a daily average sales is 800 Are the sales in store tree less than the average sales, and here I just have a small error. I just need to add in daily. There we go. True false, true faults. Now let's try and find sales that are between zero and 500. So we have an umpire a greater than or equal zero on no umpire a less than or equal to 500 . See what we get. The true value of an array, but more than one. Ellen is ambiguous. So what does that mean? Well, obviously, the and operator does not like the work on a raise. This is where logical and illogical or logical, not come in handy. Desire the num pyre a equivalent to on or not. Let's try a comparison again and this time using logical and so a slightly different syntax . So here we have an P ideological underscore. And so NP array, logical underscore and open brackets put in our variable, which is a new empire. A great honor equals zero comma, followed by another pyre a again less than or equal to 500. So, as you can see here, we're wrapping this line of code here, which is essentially our comparison operator in brackets. On passing that as an argument to np dot logical hand Let's run this. There we go. In this next line of code, we're going to explicitly select the sales figures. So we have our NP store tree sales. What we're doing now is opening square brackets and p that logical and and install a tree sailed greater than or equal to zero less than equal to 500. So inner output instead of us we've done approves examples we've been returned with a Boolean array in this example were being returned with a figure output. We've just learned about comparison operators on how to combine building results using Boolean operators on or not. Now it's time to use these new concepts to learn how you can change the behavior of our programs. With the help to control flow over programs, we can use conditional statements such as, if else on LF let's take a look at some examples now. So here in the comment, you can see we want to print out the name Tony. So the first thing we do is create a new variable name equals Tony. So we're assigning at the string, Tony. So if the variable name is equal to Tony print Hello. So this seems puts it pretty simple. We create a new variable, we say. If that variable is what we wanted to be, we print out a result. Hello, Tony. Okay, great. So let's say your name is Frank. Nothing happens. I'm going. Come to that now. In a minute. In the next example, let's check that a number is even. So. X equals eight if x modelo too, Which means X divided by two. And the remainder is zero print exes. And even Number X isn't even number perfect. We change this to nine. We don't get anything out. Put it on again. What comes out now In a moment and both examples above pipe nous check to make sure that the if condition is true in the example directly above exes, even which means the condition holds and the cold is executed. In the example below, we've added another line of code. Or if statement, this is still acceptable to piping. Let's have a look at that name equals Tony. If name is Tony Print confirming name. Hello, Tony. There we go. Now we still on example to both that let me change the name to Frank, so our condition becomes false. We didn't get an output on the same in this quick example. To get output from our script, we can add an else statement. Let's look at how we do that. So here we started off the same. We've created new variable name onto that. Very. But we assigned the name John. So if name is Tony, print out confirming name print. Hello, Tony. And then else, print. You are not Tony cannot log in. Let's just take another moment to go through this piece of code. It's pretty simple at the top over doing is creating a new variable. We then have our if statement, if name is equal to Tony. And again, we know that the Equality operator is to equal signs. Our if statement is finished with a colon. Our next line print confirming name print. Hello, Tony. We don't have an else statement on the else statement is closed off for the colon. So what the out statement does is if he both condition is not met, it would print out something else. So print, you're not Tony cannot log in. So there we go. You are not Tony cannot law again in this line of code. Let's check. That number is even. So we have the code that we used above and again we've added an else statement. So if X is not uneven number, print X is an odd number. X is an odd number because excess tree involved example to both The condition is not true. And so the else statement runs the out statement Run if and when the statement above does not hold true, the Aleph statement allows for even more customization. So what are we doing here in this code example with the Aleph statement? Well, we're creating a new variable, Tony, and the first thing we're doing is testing for a lower case, Tony. So if name is Tony Print Hello, Tony. Now test for Oprah case. Tony Aleph. Name is Tony Print Hollow. Tony Else Print. You cannot log in. So, as you can see, the Aleph statement adds us to allow more customization to our flow for that shift in Andhra. Not hello, Tony. Now, if I change the name of my variable found uppercase Tony, the lower case, the condition is still successfully met on we get hollow. Tony, if I change this to Toni with an I. There we go. Cannot log you in. What else can we do here? We have two variable to name and age. If name is Tony Print, how can I help you? Plus the string names are capitalized. Plus question. Mark just need shifting. Enter there. And there you go. How can I help you? If a is great in 18 print you were allowed to vote. We didn't get output because her age is not great in 18. Let's change our age here to 21. You're allowed to vote. There we go. So you can see the power of thes conditional statements when you start to combine them together. Okay, let's take the example to both and add the else statement. So if name is Tony Print, how can I help you? Plus string name Doc? Capitalize. We have added in here an else statement. Print. Sorry, I only speak to Tony. So let's see. Sorry. I only speak to Tony. Next example we've added else. So if age is greater in 18 print, you're allowed to vote else. So you're not old enough to vote. So let's try that. You're allowed to vote. Let's just change age to 17. And that's happening because I change this variable up here. Let's change this back. Teoh 18. Here we go. Sorry. You're not old enough to vote. Okay, let's add an LF statement. So here we create two new variables. Password and grade in the next code cell we have. If the password is equal to 1234567 Colon print. Welcome to Acme salary. So obviously we're trying to log into an accounting system or a salary based system here now Aleph. If the if the password is not 1234567 Print. Incorrect password. Try again. Alice printed creating account. Click here. So if you don't have a user name and password, let's print this out. Password is not defined because I didn't shift in. Enter and that's out. There we go. Incorrect password. Please try again because their password variable is one to treat for 568 But we're entering in 1234567 So let's try. Let's change this to match. Welcome to Acme salary. Okay, let's use the grade variable. If greatest five print, you can access the following menu items. Aleph The greatest four. Less than or equal to four prints. You do not have sufficient permissions else. Please upgrade your permission levels to run that you can access the following menu items that's changed a variable grade, too. Let's change it to let's see less than or equal to force. Let's change it. Four. Actually estranged tree. You do not have sufficient permissions to access this menu. Let's put what we have just learned to use with the pandas. Data frame in Poor Panis is PD, so create a new variable. Speaks underscore. English equals P D. Don't read. See SV on. The first argument is the location of a file index call equals zero prints speak English. There we go. Here's the data frame loaded in a nicely format. Now imagine that we would like to select the population greater than 60 million. We must for select the Population column. Next we do the necessary comparison and finally use the results to select countries. So that's for a select the population column, because that's where we want to run. The comparison so speaks English on the population. There we go. We could also use the Lok on that I look versions and here you are here to see which Rose have a population great and 60 million with simply append great and 60 million to the line above on. Here it is. There we go. False. True, true, True, false. True. True. Now we have a serious contained Bolin's. We now need to store the Boolean Siri's as a variable over 60 on How do we load up over 60 equals? So from our speaks English data set the 2015 population column anything over 60. The final step is to use the building Siri's to subset the panda data frame on How do we do that? Well, we have our data frame speaks English on we passed out the argument over 60 which is the variable assigned to here. Run that we now have rows columns of populations only where value over 60 million is applied will always the code that we have just entered. Do you think it's possible to accomplish it with just one line of code? Let's take a look. So we start off with a day. The frame speaks. Underscore English Open square brackets again were subsiding. So speaks underscore English Open square brackets. Selected COLUMN We want so population because we're interested in populations that are created in 60 million close square brackets greater than 60 close square bracket. Perfect one line of code to do what we just did, and the output is the exact same. We didn't dump I. We can also use a logical comparison operators previously seen so we can do the exact same that we did with data frames on a numb pyre. A important, um pi and p dot logical and speaks English. So that's the array. Select the column. 2015 population Great and 60 speaks English 2015 population less than 100. There we go. That's output populations Great. And 60 less than 100 million. We condemn place this code inside square brackets. The subset speaks English correctly and let's see what that output looks like. Perfect. Here we have populations greater and 60 million, but less than 100. Okay, that's it for this lesson where we've learned heightens logic, control, flow on filtering methods. When you have completed all the lessons in this class, jump over and take a look at the class project. Well, we will implement in a real world. Example healthy. How to use pie tins, logic, control, flow and filtering. Thanks for listening. I'll see you in the next lesson. 10. Python Loops: Hi, everybody, and welcome this lesson where we're going to be discussing Pipkins loops starting with the while loop the wire loop December to an if statement in that it executes the code inside it . If the condition is true, the big difference between a while loop on an if statement is not. The wine loop will continue to repeat the statement over and over again as long as the condition is true. So let's take a look of what I mean. In this example, we have a total equals zero on Wyler. Total is less than or equal to nine due to following. So the syntax of the while loop is while and then we have followed by the variable less than or equal to nine colon. And as we know, the colon will indent the next line of code. So total equals total plus one about the moment our total of zero so continue toe add one to a total and Taylor total is less than or equal to nine and then print it out. Let's see what we get. +123456789 10. Now let's do the same thing again. This time. Let's do a blast off countdown. So blastoff equals eight Wider blast off is not equal to zero Print T minus, then assigned the blast off blastoff minus one. So here we're counting down from eighth with each trip. Trudeau while loop were taking one off blast off. There we go. T minus 765 all the way down to zero. Let's modify this blast off loop a little bit. So while our blast off is not one print e minus on every time Trudeau loop, take one away from the blast off variable. But this time it for blast off is less than or equal to one print out. Lift off. So, as you can see within a wire loop, we have a nested if statement there we go. 10 T minus 10 all the way down to lift off. Or maybe I should say, blast off their Let's look at the four loop. What we've done here is create a new list salary underscore list on in that list. We've placed a number of people salaries, so it's great. A four loop. We used the key word for we then enter in an element, identify so this element identifier here can be anything salary, wages, s w whatever. It's just a word to identify each element would in the salaries list. True and federation after 44 salary in salary list. So for each element within our salaries list, print out the element 2123 29 so one. Take another look at the output from the cold example above. Do you notice anything missing? There is no access to an index in the iteration. We use a numerator help with this task which will give us two values on each iteration of the loop. So how do we do that? Well, again, we have four. But now we're adding in the keyword index salary in the numerator salary list. So for each element within the salary list in numerator with an index were done creating a prince string So pretty index plus string index plus salary. Let's see how that looks. There we go index 0 to 6 and all the salaries don't match. In the example above, the index started zero, which does look a bit strange. So let's try and start it at one. So what we've done here now is within the string function. We have index plus one that's print that out. There we go index 1 to 7. We can even it rate over characters in a string with a for loop so foresee in strings of C being for character Prince CDA capitalize. So what's gonna happen here is each time we move to the four Loop, we pull out the forced character, the second character and so on, which is assigned to the name See on. Each time we run through the four Loop, we capitalize. See, there we go, Strength. Now let's create a new list for employees and their yearly salaries. Employees equal. So as you can see here, we have a list within the list. So the Forest list contains Tony on his salary. The second list contains Jane, and her salary on the turret list contains Amy and her salary. So four staff and employees on again staff is just simply a random assigned word that we create to represent the elements within the four loop on. What we want to do here now is put the star from employees, so the elements from employees list into a print statement on How do we do that? What we say print staff on what we're doing here is we're going after the staff name at Index zero. So we're saying Staff index zero plus errands plus String Staff index one plus per year. So what this print statement does is from her lists, it takes staff. Index zero combines that with word errands. Next ads and staff index one and combines that to the ward per year. Let's see what that looks like. There we go, Tony Errands 20,000 per year. Jane Errands, Amy and okay, lets modify this a little bit by chaining capitalize function onto the staff. We can also loop over data structures. So if you're seeing, have to loop over Liston strings. But as we have seen, there are many other data structures within piping searches, dictionaries and numb pies. So how can we loop over them? Okay, well, let's start off with population data for Ireland and the United Kingdom in millions so world, it's not really world, but anyway, we'll call this dictionary world so key value pairs So the key Ireland The value 4.5 key United Kingdom, the value of 65.7. Now let's print out the key values for each key value pair in World Dictionary, and we do that with a four loop on the sin Taxes. Four. Key come a value in world that items print key plus two dashes. Just separate them out. Blustering value. Let's run that size. You can see Ireland Dash 4.5. So as you can see an example of both, we introduce a new method, which is items this will produce a key value in each iteration. Dictionaries are by their nature on order, meaning that the order in which there it rate over is not fixed so we can also loop over numb pie. Raise on. How do we do that? Well, let's start off by importing dump eyes MP. Next, Let's create new list. Let's call that list salaries and then that's creating new variable called MP underscore salaries on India's variable. We're going to assign an umpire a composed of the elements within the salaries list. So let's loop over this new empire A on We do that with a four loop that it rates over all the elements in N p underscore salaries, so four s an MP on the score salaries. Print your assemble plus string plus per year. There we go. So if any of this is a little bit on familiar to you, or you would like a refresher than encourage you to jump in the part one off this learning Siri's. So we're in part two of this learn data signs with fightin, but there is a part one on in part one, we explored some of the more basic concept, including how to convert into just two strings, which we just don't hear, as you can see from the example above. If you're dealing with a one dean umpire, a looping over all elements can be symbolized. Four. X in my ray, if whoever you're working with a two D number numb pyre A. It's slightly more complicated. A to D array is built up of multiple one the rays to explicitly iterated overall separate elements of a multi dimensional array. You'll need the following syntax four Act in n p dot nd either brackets my underscore array cola. Okay, let's take a look. A look at another example of iterating over an umpire, a again important umpires MP here We have to list and P salaries, which be converted to an umpire A on MP employees. So what employees are earning what salaries? Now we're going to combine these two Umpire A's so combined underscore details equals np dot array square brackets and P salaries. Combat NP employees. Okay, so we've combined to numb pie raise into one called combined details. What we now want to do is iterated over combined details, So four valve but his values four. Vow in combined details. Print the value. There we go. Perfect. It's also possible to loop over pandas data frames. So let's visit our country's list from a previous lesson. Import Pandas PD. Let's create a new put data frame called Speaks Underscore English on to create that data frame, we need to assign it some data. So used a function p d don't read underscore CSP. The first argument is the location of our data set, which is called Speaks on the score English that CSB on. Let's give it an index call value of zero. Let's use a for loop to it right over the values within our speaks English data friend. There we go, so four values and speaks English print values, but we have His country speaks English 2015 population, So it's looping over the column names In Pinas. You have to tell piping explicitly that you want to it rate over the rose. To do this. We call the Inter Rose Method on the data frame. So what we're saying here is four. Label or lab. So four lab comma row in speaks English, not it arose. Print the label printer row. What, you think that's gonna give us perfect? So here we have our index i e u k d e. So we're seeing these indexes and labels in previously lessons because a role variable on each iteration is a Siri's. We can easily select additional information using the so upsetting techniques that we learned in the previous lesson. Imagine all we want to print out is the population. For each iteration, we can change the print statement as follows. So for label row and speaks english dot it arose. Print out the label separate widely separated by colon on convert the 2015 population row data into a strength. And there we go, the index and the population of each country printed out and it's example, we have just printed the labels on the capital together. Let's do something a little more advanced and at a name length column toward data frame. This column a count the number of characters in a country's name. So how do we go about doing that? Let's create a new data frame. This data frame is gonna be called speaks English on Inside is going to be PD don't read. See SV. So we're adding in some data, so the data set speaks. Underscore english dot c S V. So the four loop is the same as previous example four Label comma row and speaks on the score english dot It arose so Israel over each row so we can select the country named by using row square brackets country on passing a true the length function. We don't need to add this new information to a new column. We do this using Lok, which is label based. So how do we put all that together, or how we make sense of what I've just said in this line? We have the name of her data frame dot lok. So using location based lab, which is a label on adding a new column called name length onto this column assigned the length of each country print out are updated a frame. Okay, so he go Name length of Ireland. Seven. The name length of United Kingdom is 14 now, because intuitive on its A four loop, it goes through the loop each time on updates. The loop. So are on this first on the list, then it's the United Kingdom. Then it's Germany and so on. So it's OK, but it's not very efficient because, as you can see, we are creating a serious with every iteration. This might be acceptable for a small data frame like we have here, but not when we're dealing with a much larger data sets. A better approach to calculate. An entire day to frame column is to use the apply method on how we do that. Well, again, we create a data frame here. We don't need a four loop in this example. So what we have is speaks English. We're gonna add in a new column called Name Length equals Speak English Country that applied length. So did a new column name length hot in the length of each country would in the country column. Let's print that out. There we go. Perfect. New column. Critical name linked, which we assigned in here and then the character linked off the name of each country. So aren't has seven characters United Kingdom as 14 characters and so on and so on. Pretty amazing stuff. Apply calls. The length function would eat country name as input and produces a new array we just stored as a new column Pretty nice. And then finally, let's clean it up a little bit more. There we go. We've capitalized are country names cause, as you can see here, it's Ireland location. I've Kingdom lower case and so one we just capitalized each one. OK, that's it for this lesson on. As I mentioned at the end of the previous lesson, we're gonna have a class project on in that project will be putting what we just learned here to use. Thanks for listening. And I'll see you in the class project