Pandas and Python For Data Analysis and Data Science QuickStart Tutorials | Henry Palma | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Pandas and Python For Data Analysis and Data Science QuickStart Tutorials

teacher avatar Henry Palma, FinTech Data Engineer and App Developer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

38 Lessons (4h 55m)
    • 1. Introduction

    • 2. Jupyter Notebook Installation

    • 3. Using The Jupyter Notebook

    • 4. Introduction To Pandas

    • 5. Data Analysis 1: Loading and Viewing Data in a DataFrame

    • 6. Data Analysis QuickStart: Viewing and Selecting DataFrame Data

    • 7. Data Analysis QuickStart: Adding Columns to a Pandas DataFrame

    • 8. Data Analysis: Aggregating Data using Groupby and Pivot a Pandas DataFrame

    • 9. Data Analysis Plot a Pandas DataFrame

    • 10. 8 Techniques to Create a DataFrame

    • 11. 10 Ways to Filter a DataFrame

    • 12. 10 Techniques to Filter/Search a DataFrame

    • 13. Using the ApplyMap Function

    • 14. Using the Map Function

    • 15. 6 Techniques to Export a DataFrame

    • 16. Create A Pandas Series

    • 17. Analyze a Pandas Series

    • 18. Search and Filter a Pandas Series

    • 19. Update a Pandas Series

    • 20. Intro To Python: HelloWorld

    • 21. Intro to Python: Keywords

    • 22. Intro to Pyton: Variables and Datatypes

    • 23. Intro to Python: Math in Python

    • 24. Intro to Python: Strings in Python

    • 25. Intro to Python: Output Strings using .format()

    • 26. Intro to Python: Using the Standard Lib

    • 27. Intro to Python: Getting user input

    • 28. Intro to Python: Decision Making in Python

    • 29. Intro to Python: For loops in Python

    • 30. Into to Python: Lists in Python

    • 31. Intro to Python: Sets in Python

    • 32. Intro to Python: Tuples in Python

    • 33. Intro to Python: List Comprehensions

    • 34. Intro to Python: Working with Dates in Python

    • 35. Intro to Python: Creating Functions in Python

    • 36. Intro to Python: Creating Classes in Python

    • 37. Intro to Python: Creating and Using Exceptions in Python

    • 38. Intro to Python: Lambda Functions

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class


This program is designed for professionals curious about data analysis and data engineering with Python and the Pandas Data Analysis Library. You don't need to be an experienced programmer to learn in these tutorials. I will give you some code and explain how it works. You will be able to take that code and use it in your day to day learning. In my experience learning to program really boils down to learning some code and then tinkering until you understand how things work. This program is designed that way.

Meet Your Teacher

Teacher Profile Image

Henry Palma

FinTech Data Engineer and App Developer


Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction: Hello and welcome to building teach. My name is Henry Palm A. I've been a business technologist for the last 18 years, working in various financial institutions and technology consulting firms have worked as a data analyst as a data engineer, as a software developer and his technology manager, And I love to teach and learn new technologies. Now this program is the Python Pandas. Quick start Tutorials Things Program is designed for busy professionals that are curious about data analysis and data engineering using python and pandas. And you don't need to be an experience programmer to learn on these tutorials. I give you all the code, and I explained to you every single line of code that I give to you. And then I give you additional techniques that you can use to learn on advanced your knowledge of both pandas and python. And I also include a tutorial, a whole section of the python language to get you started and to get you more experience as a programmer. In my experience, it's best to just grab some code, tinker around with it, and in order to get your learning, I hope you join me in this program, and I hope you enjoy thank you. See in the next video 2. Jupyter Notebook Installation: Welcome back to building teach. In this tutorial, we are going to be installing the anaconda Jupiter notebook. Um, to download the anaconda Jupiter notebook. Goethe anaconda dot com for its last distribution, which is the download page. Select your operating system and click the version 3.7 of python. I've already downloaded this. It takes a few minutes. And when you click on that package, it will give you this install and a kind of three dialogue. Just press, continue. Uh, just basically follow the instructions. It will take you all the way. Just install it and its default location all the way down. It's installing which this This will take a few. Maybe a minute or so. Okay, Once it finishes installing, you'll see the insulation was completed successfully. Just close, move into the trash and just basically click on the anaconda Navigator icon. This will open the navigator, which gives you a button to open the super notebook. And simply here it is. This is the navigator here. We'll be using this, uh, section here, this launch section here of the Jupiter notebook. Just click on launch, and that will start the Jupiter notebook. And it will open in your home or your files page. Right. Your home and files page in here you should do is you should create a working folder. So I just go to new folder, all right? And it's going to create a new folder And on, uh, untitled folder right here. See, a few seconds ago entitled, Just Simply go and rename. Call it whatever you want. I'm gonna call it working Holder the name, and then double click on your working folder. Once you have created a few of them here and here, you've got a an empty working folder to create a notebook. Simply press new Python three and that'll open a brand new Jupiter notebook window on here . You can change the title. Say, my first project on Now you have a title on the project. In the next few tutorials, I'll give you some brief instructions and how to use the notebook s so that we can get started. We'll be using notebook throughout the entire tutorial, both for the python tutorials and the pandas tutorials. All right, so I'll see you at the next video. Thanks. 3. Using The Jupyter Notebook: Hello. Welcome back to building. Teach in this lesson. We're gonna learn how to use the Jumper notebook. As you can see, this is the section we left off at. This is the brand new Jupiter notebook page that we created in the last lesson we rename this my first project. Now, the way the notebook works is it has thes cells in here. So this is cell number one and the cells have different types. There's a code cell, which is this one here. You can tell it to co tell because it's got this in with square brackets next to it on. We also have marked down cells. You can tell it's a mark down south because it doesn't have an in. Now, those are the two main ones. You're gonna be using code and mark down. There's actually a keyboard shortcut you can use. So if you click outside the cell if you click M, as in Mary, it will make the cell a markdown cell If you click. Why, as in yo yo, it will make it a coat. So now all the code we're going to write is gonna be written in a code, so this right here is a coats up. If I press enter, uh, I could make multiple lines. If I press shift entered, it will create a new sow, a new coat sell right under it. But shift editor will also execute code. So let's try a really simple hello, uh, world output here. So I have here the print command with the open bracket and open parentheses. Close parentheses with hello, world inside this that you print in pay phone and I'll go over that in the paper. Mandatories if you're not familiar with eso just right for now, print, open parentheses, whatever you want. I'm writing hello world and then closed parentheses and then press shift, enter. And as you can see, the output of the print statement will be shown right below yourself. Another cool thing about cells, eyes that you can actually store variables and share variables all the way down. So if I create a variable here, I'm gonna say name. And I'm gonna put my name Henry in a press shift, enter Nothing's gonna happen, is that I'm not. I'll put it anything. If I write print name here, it's gonna know about name because all of the cells here share the same data. If I press shift, enter it will look at the prior sulfur name and it will write my name here. So it's pretty simple. The other type of cell we have in the Jupiter notebook or the other type of Maine. So all we have is theme mark up so you can change the cell to Mark. I'm starting marked down so you can change the cell to mark down by clicking on this drop down box here, and you can see here it's now mark down Saw because it doesn't have this in. You can also make it a markdown solved by using the keyboard shortcuts or click outside of it and click em. Now, a marked outside is really just to display formatted text in your notebook. So if you wanted to have some type of heading, you could write formatted texts and I'll go over a few small ones right here. One of the main ones you'll be using is through the headers. Uh, tag. Here are the headers symbol here. So I'm gonna say, uh, my, uh, Mark gown pile. Uh oh. And this is similar to the H one hour header one in HTML. If you want an H two, uh, her to Orrin H three, each one each one that you write will get smaller, right? Three. Now, to execute this out, same as the coat sell shift, Enter and you can see here. Now you've got this formatted text displaying in your mark council to add it. The tax just double click on it again. Let's create a list here to create a list used the hyphen symbol. I'm gonna say I don't one and then hyphen symbol to again. I don't to and I don't three pressure center. Now you can see I have a bulleted list in here. So Marc Gonsalves receiving Use them a lot. Teoh separate each section of the Jupiter notebook for whatever particular lesson I am covering. But that's really all you need to know. For now, I have a section within this entire series on mark down. So So it's an optional section will see at the very bottom of this of this you Demi Siri's . So try that out. If you're curious about writing tables about bringing in HTM Mao or latex formulas or or um Oh, formatting like, bold and italic and stuff like that. Please take a look at that optional section. But in the next tutorial, we're going to start coding in Python. Uh, Independence. So join me the next section. Thank you. 4. Introduction To Pandas: Hello and welcome back to building. Teach in this to Tora. We're gonna have the introduction to the Pandas Library. So Pandas is an open source data structure and data analysis library For the Python language. It's it's used by data scientists by data analysts by any programmer needing to manipulate data. It's used a lot in academic research analysis for statistical analysis and scientific analysis, and it's used heavily in software engineering projects. I myself used dependence library at work. I work in the financial sector. So the the way I use it in a typical day to day is really to source data on to do what we call data engineering to source data from various sources and to enrich the data. Modify the data on show the data in a way that users can gain insight, which is similar to the way data scientists use use the data. So in pandas, there are two main data structures. The first data structure is called the Siri's on the second date of structure is called the data frame. Now the data frame is by far the most common data structure that people use independence library use. But the series is also a very valuable data structure, so we're gonna learn both in this program. Eso the Siri's is a one dimensional labeled array, right? So it's one dimension. Meaning has one column of data, and it has labels. It's a labeled array. You can think of a Siri's as a mix between a Python List or python dictionary. If you're familiar with that, if you're not familiar with that, don't worry about it. I have a whole section on python lists and python dictionaries in this program within the Python Basics section. But for a brief intro, you can think of it like if you're a heavy Excel user, you can think of a Siri's as a table with one column in it. Well, basically two columns, because you would have in a labels condom. But your data is the one comes a table with one column of data, right, as you can see here, here I have, ah, a series of weather for the Texas, uh, cities in Texas, right? So a Siri's has a name attributes so you can name your Siri's that way. In case you forget what data is in the series, you can name it has an index. And it has data, right? Pretty simple. The data frame is the other, and it's by far the most common data structure and python. So the data friend is a two dimensional labeled tabular structure that supports multiple types of one Come and buy two dimensional. I mean, this is basically a table, right? It has a column, uh, dimension right here. So this is the X axis, the column dimension, and it has a row dimension here. So this is the x of the Y axis. Right. So you have your index on the rose, and you haven't index of columns on the columns on the on the X axis, and you can think of it if you're If you're an Excel user, you can think of it as an excel table. So in this particular data frame table, you have three columns of data and you have one labeled index. Right? So this basically gives you the temperatures for ah couple of cities and in Texas by day. So here you have all the temperatures Monday off or the temperature for Tuesday. So you can think of it as this table in memory table that you can analyze that you can modify that. You can pivot on that. You can select and filter, and that's basically the overall concept of data frames. In the next few tutorials, we're gonna dig into both creating Siri's and data frames. If you're not familiar with Python, you should be OK because we're basically just digging in to these two data structures in the next few sections. After that, we go in depth into the python language because it's it's it's It's enough for now to know how to use a data frame in a serious to be able to analyze data. You don't have to be a an experienced programmer to use the Pandas library to analyze data . But if you're going to start creating functionality, if you're gonna start creating new columns that require some programmatic logic, then you do need to know the python language. And we have a whole section in this program about the python language, and each of those sections even have exercises that you can try and cheat sheets that you can use. This section also will have from cheat sheets that you can use that will hopefully become a useful to in your journey into python. So let's get started. We'll see you in the next video. Thank you 5. Data Analysis 1: Loading and Viewing Data in a DataFrame: Hello, and welcome back to building teach. And this section. We're going to start the data analysis portion of this program. Now, in the data analysis portion, you don't have to be an experienced python programmer. My goal is to teach you simple techniques that you can re use every day to perform data and analysis on pandas data frames. So let's get started. The very first thing you need to do is go to your resource is folder within this section of the videos and download the sales dot C S V file that I had put on there for you on what you basically have to do is you need to go to your working directory. I've called my working directory data analysis. Go to your working directory. Click on upload. Click on the sales dot C S V file that you've downloaded from The resource is folder. Click on that and then upload that file. The next thing you need to do is create a new python notebook. So here's my new python notebook, and I'm gonna call this Python notebook. They, uh now this is one. Okay, so the very first thing we do is import the pandas library to import dependent library. You type import pandas? Yeah, as PD. Right. So that's the very first thing you need to do. You need to import the pandas library. The as PD is simply an alias. It allows you to rape PD instead of pandas. And it's the standard way to write your import statement for pandas. The next thing you want to do is you want to create a variable. Sales equals. You need that read CSP sales that CSP. So this read see SV function of the Pandas library reads your local CSP, the one we just uploaded, and it creates a data frame out of it. So to view that data frame, you should write sales here. And as you can see here, we have now created a data frame out of CSP file, and you can see that this state of frame contains sales data. Has few columns as a date. Com on associate column, Your product quantity, unit price and unit costs. Now If I wanted to go and I wanted to count, let's say we're doing a quality check on your file. You want to count how many rows on columns this data frame has, he would use the shape attributes of the data from So you just write sales that shape and then you click, shift, enter. Remember, shift enter for cold cells in order to execute it sells. You would have done shift. Enter here to show the data famous well, so shift enter and you were right sales that shape. What this basically gives you is it gives you the roles, which is the first object here and on your columns. With this. 14 rose and six comes. If you had a file that you were expecting, let's say 300,000 rows. But when you check the shape it had 1000 rolls, then that's the first quality check you would do to make sure that you uploaded the correct file. If you just wanted the roles, you would do sales that shape and then square bracket zero zero, because what this shape attribute contains is it was called the to pull in python and Tupelo is an indexed container, meaning that it is has numeric indexes for each object within the to pull. So the first object in the to pull is zero. It's the index starts with zero. So 0123 So this is zero. This is one. So if you want to return the number of roles and the data frame, you just say sales that shape zero Press shift entering. You can see here you have 14 rose in this data frame. If you wanted to see the column count sales that shape one, and this would give you the column count of your data frame. If you wanted to see what the data type your data frame is, you would use the D type attributes. So if you click on the type sales that tape the types within US policies, the types it will give you the data types of each of the columns object in the data frame. As we saw from the data types. Tutorial is a string to its storing the 1st 3 attributes of string. It's storing the quantity as an int, and it's storing the unit price as photos. You can see her as a decimal point here, so that's the first part. Try these out and I'll see in the next tutorial 6. Data Analysis QuickStart: Viewing and Selecting DataFrame Data: Welcome back to building teach in this section. We're going to continue our data analysis with Penda as data frame. From from now on, I'm gonna have the code available here. And I'm going to also include this notebook as a resource within the videos. That will give you a little more time to look at the code and little time More time for me to explain the code without having to deal with all the typing within it. Uh, let's get started. Eso first. Let's look at our data friend here. I've got the sales data, friend that we load it in the last tutorial. Now, let's say I don't want to see all the columns. I just want to see one column and I want to see one common in particular would see the Associates column. Now. The way to do that is you use this in tax right here. So I've got associates Variable. You can call us whatever you want. Call it ABC. I'm calling associate, so I know what I'm selecting. And then I have the data friend name and square brackets and then another square brackets. Then the name of my column. And then closed the two square brackets. Now the reason for the two square brackets is that the inner square bracket is actually a python list, so it will take more. It can take one or more column names in here. In this particular exercise, I only want to see one column name, So let's see what that soldier. I'm gonna execute the cell. And as you can see here, it gives me the data and let's take the head out for us. You can see gives me all of the rows, all of the rows for the Associates column, right? So let's just put the hat just to say from space. Hi. So let's say that's useful if I just want to see all the rose for the Associates column. But let's say I want to see the distinct values within that common. Now that's pretty simple. It's the same exact code as I have appear. The only difference is, I add, the drop duplicates method to it. So if I add the drop duplicates method to my sales square bracket square bracket associates , you can see that it gives me the distinct values within that common. Now that that's a very common exercise when you're looking at a data set to, let's say you're looking at a data set of states or something like that. Oh, our tax revenue by state or something like that, and you want to see how many states distinct states are in your data set, You would do this exercise right here. You just select your column with the two brackets and drop duplicates and you can see here . These are all the associates, these air distinct associates within the associates condom. Now, if I want to see more than one column, if I'm gonna return more than one condom but not all of them, I would just put the columns that I want to return here, have associates and product. If I execute this code, you can see it gives me all of the roles for associates and product again. If I want to see the unique combinations of these two condoms, just add to drop duplicates method to the end and give me the unique combinations for these two columns. Now let's say I don't want to select specific count on us like specific Rose and I specifically want to select all of the rows with the associate equals Mike, right? So it's a similar format sales square bracket, and then sales square bracket associate square closing square bracket equals to Mike. What this will return to me is all of the roles we're associate equals Mike. So you follow this in text sales square brackets that your data frame and the column that you want equal equal. Mike, if you didn't want to see my little you want to see that, Mike, you would just use the exclamation point. And when you do that, you will return or off the rolls, where its not Mike. And in this particular example, there's only two associates as we saw here from two distinct is John and Mike. So it gives me all of John's, uh, Rose. If I wanted to look at something with a value in it, the very similar format. So here I want the unit cost greater than 500. So same format sales, square bracket and name your data frame or both of the name right unit costs greater than 500 years. This form here and you can see it gives me all the unit costs greater than 500. And I can also do less than 500 here. And you can see these are all the unit costs less than 500. Now, try these out. We've learned how to, uh, select a subset of columns, one column or multiple columns. We learned how to get distinct values from these columns. Way learn how filter rose by a value here by Mike or not Mike and Filter Rose. Where has a numeric value? Try these out and I'll see you in the next video. Thanks. 7. Data Analysis QuickStart: Adding Columns to a Pandas DataFrame: Hello. And welcome back to building teach on this tutorial. We're gonna continue our journey into the data analysis using the pandas data frame. And in this particular tutorial, gonna learn how to add columns toe a data frame. So let's get started. First, let's load the data frame that we've been working with. So we were reading the CS file that I provided in the first data analysis tutorial, and I've loaded that CSC far into a data frame. Now let's say I want to add a column. I want to add the sales month to my data frame. Let's see, Let's see that work. Right. So I want I want to do this. I want to add the sales month and I want to add a static value. Right. So this is the sales data for February. So I want that last column to be forward. The way you do that is you write the name your data frame, then square brackets, sales month. So this is your new column name, and then you said it equal to some value. Right? So you're right, you're the f make a column B f f name, uh, new column name and then people. To some, that's basically all doing here. So I have my data friend name my new column name equal to some values you can see here. It adds a static value and a new column to my data friend. Pretty simple. Now let's say I wanted to add a calculated or computed column to my data friend. I wanted to add a condom for revenue. And revenue is basically the quantity Times two unit price. Until this is your gross value, your gross profit right here you're gross revenue, gross revenue right here. So basically, let's take a look at that. So basically, I want to add this new revenue column here, and the way I do that is I take my sales that quantity, right times sales, that unit price. So this times this equals revenue. And this that's it. It basically adds a new computed value to my data friend so sales dot com name and times sales that in their price you could do that with any any math function with location, divisions, traction, etcetera. Let's say I want to add my unit cost my and my cost right. Total cost. So total cost in here. Total cost in here is quantity, times unit costs. So the way I do that is here again, my data frame, the new column name equals my data frame column times the other data frame common equals, cost and you can see here. And it has added a new cost column to my data frame. All right, so now let's compute the prophet. The data from the prophet is revenue minus costs. So again, data frame, new column name equals data frame column. So I have revenue minus costs, and that will give me my profit. As you can see here, stick it out with the old table So you can see here then. Now I've got my revenue. Uh, minus cost equals my profit. Pretty simple thing is just simple math to add a new column to my data friend. Now let's say I wanted to get a little fancier and add some logic to my data frame. So let's say I want to compute a bonus and a bonus on Lee. If if the sales person sold a refrigerator now, the way I would do that is I would do that with the apply function of the data frame and the apply function takes as input some formula, some function. And what I'm gonna do here is I'm gonna add what's called a lambda function. Landau function is an unnamed function within python. So the way the syntax of land is lambda and then your argument pro, which is nothing more than a variable, and then the expression that you want to calculate. So in here I'm saying 100. The value should be. I mean, let me execute us. You can see it. The value should be at 150 if the product is refrigerator. So anywhere with a product is refrigerator. I want to add 150 else. Zero. So the bonus for this month. Let's say if you sold a refrigerator, you get $150 bonus. That's pretty much with this insane. So you would use this format right here. You'd use a land expression Lambda Row and 150 if roll dot product equals refrigerator al's zero. And as you can see here, access one so the apply function, and I'll explain that in a future video, the apply function is able to apply a a some code either to the row or to the com access. One means applied this code for every single role. If I had put Access Zero in here, it would do column functions. And I'll show that in a future tutorial in the future of video. And you'll see that later on. Um so let's say Okay, I don't want to use a lambda function because Lambda seems a little complex, which really isn't. Get your Salambek choose heavily in Panda's for formulas. But let's say I am familiar with Python and I want to use a python function eso in here I have a python function called sales cut, which takes as input, bonus, profit and bonus. And basically, what this sustain is my cut is 20% of the profit, plus my bonus, right? If I if I execute this, you'll see I just remove the head so you see the whole thing. So basically it's saying profit times 20% plus my bonus, right, so in here, 20% of 12 50 is 2 50 and then, since I don't have a bonus, it's just 2 50 on then. 20% of 800 calculator here 800 times 0.2 equals on 16 plus 1 50 bonus equals 10. And as you can see here, it's through 10. So it's basically putting this function and the way you do that, uh, is again used the Lambda. But instead of doing the if statement, you put the formula in here. You put the function in here. So in here I have sales dot seals cut equal sales that apply Landau role, Robien the variable and then sales cut. That's my function. And then as input, I have RO right. So my row profit right for profit and roll bonus for bonus and again and access one, it's this is executing for every single room, and it will calculate this function for every single role. No, if I wanted to. Let's say this is the report I actually wanted. If I wanted toe out, put this to a C S V. So I can look at it. Let's say an excel or in some other tool I would Then I would say sales that to see SV equal sales report and that will land the report inside of your home directory. And you can also let's say from here, and I go to my work in folder and I want to take this sales report. This will open that report in numbers because I'm using a Mac. But if I had excelled, it would open it in Excel. So try that out Way tried a few things within this tutorial. We tried first adding a static column. As you can see here we had in February to the sales month, we added a few computed columns. Revenue cost, profit. And then we added a a more complex logical column, using an if statement to calculate the bonus. And we added a sales cut using a python function. So those are the many ways to at a column toe a data friend. And then finally, we exported this data to a CSP file so that it can be distributed or analyzed by other people. Try those out and I'll see in the next video 8. Data Analysis: Aggregating Data using Groupby and Pivot a Pandas DataFrame: Hello and welcome back to building teach. And this story we're gonna learn how to aggregate data using both the group by and pivot table functions of the pandas data frame. Now, in this one, we're gonna take a little bit of a different approach. The last tutorial we saved this sales report, which is pretty much all of the work that we've done up till now, or we've added columns of data calculated columns of data. So we'll use that as our data friend. No. When you did the to see SV of the sales report, it added that sales report to your working directory. So it should now be available to you in a two to be used in your notebook. So created a new notebook and let's get started here in here. I have import Pan is a speedy and I'm reading the sales report. As you can see, it brings it in exactly the way we left it. All right, so here, we're going to start aggregating data. I'm gonna aggregate. They're using the group by my now. When used a group by method, it basically sums up each of the rose by the columns that you select. So let's let's run it and I'll explain it. So in here have sales by associate using group by. So I basically have my associates and their revenue, profit and sales cut, and it sums up all the revenue or the profit and all the sales per associate we do that is , you bring your valuable name equals your data frame Name square, back at square bracket. And again, the second square bracket in here is a list. So in here, I'm grabbing a list of the fields that I want to use from my data friend. So I want associate, I want revenue. I want profit one sales and I want a group that data by associates I'm gonna aggregate by associate And the function that I want to use is the sum function here. So just follow this method sales data square brackets than the list of fields you want that group by then, the group by field, you want a group by and then the function that you want to use when you use a some functions. But this is basically doing is summing the revenue, profit and sales cut by associating and notice the way it it creates a table. It sets the associate as the index. You can see here that this is now the index. But if you want a flat table, that's what you want. To show this in the report or something. Just reset the index and it'll flat on the table for you. So you see here and now it has associate revenue profit all in the same level. Oh, pretty easy. Um, let's say you wanted to calculate sales by product. So instead of selecting associate, you select profit revenue. I'm a sort of product revenue and profit, a group by product. You execute this and then notice what I've done here. So what, I mean, not execute this one here. That's just Oh, so in here I have my sales. I select the field. I want to filter. I want product revenue profit, Group five product and I want some some function here on you notice here. It gives me the revenue product product, but let's say I wanted to sort I wanted to sort the revenue from from in ascending in descending order, right? I want a sort The reb I want to start the revenue in descending order. And as you can see here, it's done that Oh, wait, I'm just to take this one. You can see here now it's done that. So it's got product sales. That sort values short values is the way to sort your values in the data frame. So here I'm saying sort values by revenue and ascending and descending. So default is ascending, so it's in descending order. You can see here it's from high to low. If I don't include that, it will do it from low to high. You're gonna see here. And of course, you can also sort values by right A so you can see here. All right, so the other way to aggregate data is using the pivot table. Now, if you've used Excel, you've seen pivot tables before. Basically, it aggravates data in a more calumnies from a fashion you can. So let's execute this. You can see you can see here it is not. We're now pivoting data for revenue by product. It's a different way to see the group by Does it in a more ro based approach, but the pivot does it in a column base support. So if you want your values to be column headers, you would use the pivot table. And the way you do that is have here, uh, sales pp. Let me call it. That's what fuse with the other sales, right? So salespeople equals PD. So pandas that pivot table and then you bring in your sales data. So this is your data, and then your values would be the value that you want to aggregate would be your revenue. Your index would be your sales month on your columns would be product. So if you don't accept before you know that you select your index would be the data, right, your columns would be the columns, and then your value would be the value feel that you would aggregate by. So in here it's and your aggregate function, Right? So in here I brought in the num pie library we've seen in Umpire Library in other tutorials . So it's it's basically just a or you will see. Actually, we'll see the num pie library and other tutorials. Numb pies heavily used with pandas. Eso when you want to use aggregation functions, numb pie is usually the one the one library that we use in here. I'm summing the sales revenue and of course, you can also reset the index to flatten the table. As you can see here it flat as a table and you can also melt the table meaning instead of going in a condom based, it actually brings it back down. Tow row base approach So it melts it by pivot in the access, uh, off the columns. So try these out. These are two ways to aggregate data in Penned is on C in the next video. 9. Data Analysis Plot a Pandas DataFrame: Hello. And welcome back to building teach in this eternal, we're gonna go over plotting data frames. Now, this is the last video of the data analysis portion. And next, a few videos. We're gonna dive a little deeper into the different ways to do things in in pandas. So we're gonna learn how to create data frames, like, 10 different ways. How to export data frames too many out to many different output formats. How to add calms of data frames in using various techniques. Except so stay tuned for those. So let's get started at this one. So we're gonna continue using the sales report, see, SV that we created in the last tutorial. So that's, uh that's view that right? Okay, So here's the data frame that we've been using. We're gonna also create a group by, so we're gonna prepare some data for plotting. Now, what I want to do here is I'm going to create a group by of associates revenue by associates. So what I did here is I called my data frame. I I'm asking for two columns associated revenue, and I'm gonna group by associate using the some formula toe aggregate that data and you get this data here now, What I want to do is I'm gonna create a pie chart from this data to create a pie chart. You used a plot method or the actually Platt object on and it's pie and plot that pie. So it's the plot object pie object. And here's a constructor for the pie. So what this basically does is it creates a pie chart of the data. So it's the The format is data frame dot plot dot pie. The why access is the data access this fig size has to do with the size of the figures is a five by five figure and I put in the auto percent, uh, with a format in here soder percent meeting. I want this the percentage numbers to be to have a percentage sign and to be float values. So, as you can see here, I've also set the title of the pie chart as revenue by associate. So pretty easy to lines of code. And you have yourself a nice visual representation of this group by date, afraid the next thing I'm gonna do is I want to create another group by data frame. This is revenue by product, the same technique as when we used. Before. I call my data frame, I select the two columns that I want to display and the group by. So I want a group by product revenue by product, and I want to make sure that I'm aggregating using the some function here. I put my data frame on. This time I'm gonna create a bar chart. So here I have data frame dot plot dot bar again. The Y axis is the data that we're presenting, and I've set the figure size 25 by five. And I've also set the title revenue by product. And I've said the Y label as revenues you can see here it creates a bar chart off revenue by product. So pretty simple. A couple of lines of code. You have a visual representation of your data. Try these out and I'll see you in the next video 10. 8 Techniques to Create a DataFrame: Hello, and welcome back to building teach. In this tutorial, we're gonna learn how to create pandas Data frames. If you remember from the data structures tutorial, the data frame is the most common data structure. Pandas. Uh, data frame is a two dimensional labeled tabular structure that supports multiple types in one column. So it's Each of these columns will support multiple types. Eso the two dimensional has to do with the column labels. So this would be the X axis and the index labels. This would be the why access. So, as you can see, a data frame is basically a table. Um, to create a data friend, use the data frame constructor it takes as input data. So the data that you're gonna have within your columns it takes the index label so you could supply the index labels. If you don't supply the next labels, it'll just use numeric labels. Starting at 012345 etcetera. It supports column labels again. If you don't provide common labels, it'll create them for you again. America 1012345 on. Then accepts data types. You can specify the data types per column in this tutorial had create an empty data frame. How to create a data from with random values had to create a data frame from a Pandas dictionary upstarts from a python dictionary from a python list from a local CS we found from an online CSP file from a local Jason file and from an online Jason foul. So let's get started. So it's created anti data frame. You just need the data frame constructor. You import Penders SPD data equals P D dot data frame. And then you just print to data Family could see here that it creates an empty data frame with no column data and no index, no index is it didn't create an American because you don't have data. So that has nothing to really Phil in, uh, within here. Let's create a data frame with random values, so sometimes, if you don't have any data, you just want to mess around with pandas data frame. You can create one out of random values on. I did that here. Using the random into method of numb pies are imported numb pie, as in p import Panda SPD have a variable here, random data frame equals PD that data frame np dot random dot rand int with a floor off 20 and a ceiling of hundreds or values between 20 and 100 and a size of six by six with a six by six matrix. I've also specified my index labels eso the Y zero to y five and my column labels eg zero x five. I run this. You could see that create 26 by six matrix with values within the matrix between 20 and 100 random values between 2800. So you can see here. This right here is a data frame of empty ever of random values. Now, if I wanted to create a data frame from A from a python dictionary, there's two ways to do it. I could take a role based approach where I specify the data in the rose one by one. Or I could take a common base approach where I specify each column and its data one by one . So here this is the row base approach to run its you can see what what's going on within the role base approach. I create a list of dictionaries and the first row would be Houston, right? So I have city as my label. Oh, are key key value pairs in the dictionary, so it becomes a label, right? So City Houston, Monday in 99. Tuesday 90 Wednesday, 100 so you can see each one of these dictionaries creates a row in the data frame. So the way you create a a data frame with a python dictionary using the role base approaches, you simply add the list of dictionaries. Aziz your data. Ah, value within the data frame so you can see here. I passed this weather list of dictionaries to my data frame, and it creates roles for me. If I had a column data instead, I wanted to specify the columns off the data frame. I could do the same thing using a dictionary where I specify each column in its data. So the first column will be city. So you see Houston, Dallas, out, Paso, Houston, Dallas, El Paso and then the next common would be Monday's weather. Monday, 991 10 99 on then Tuesday's weather and then Wednesday's weather. So that's how you create a panda's data friend using a python dictionary in the column based approach. You can do the same exact thing with lists You could do the role based approach for lists, right? You create a list of lists where I specify my first role. Houston 99 1 10 $99 9900 And then I specify the columns in a separate list. So to create a data frame from a python list using the road base approach, I wouldn't use the from records method of the data, friend. Right. So I have here, I have my weather. So this is the data row base data. I have my columns. This is a list of my columns, and I used data equals PD that data frame from records where I passed the data first. All right. And then I specify the column. Data dot columns equals call. And you can see here that it creates the state of him. I didn't specify the columns. Just if I just went on and just brought in the data. You can see what happens in the data frames it creates. The comes for you using numeric values in C 0123 But if you have, if you know what your columns are specified the columns and the list and pass it to the columns attributes of your data frame. And you can see here now creates your condoms if you were gonna go. The column based approach is that of the row base approach. You would specify each of your columns both your columns and your index, plus the data within each calm. So here have my columns City, Monday, Tuesday when they have my city. So the very first column would be city. And I would say, Houston, Dallas Paso the data from Monday, the data for Tuesday, the data for Wednesday. And then I would call the PD that data frame to create an empty data frame. And then I would specify Age Column So my first column would be city and I would pass the city data. So this is this is a very similar pro. So what we did in the first part of this tutorial were created after data from and that were filling the date of thing. So you, in order to fill in order to create columns in the data friend, you just specify the column name data, and then the column name and then you pass the data Twitchell City. Then the next column would be Monday, and I passed the data from Monday. Next column would be Tuesday positive for Tuesday. Next common would be Wednesday in the past the date of Wednesday. You can see this is a pretty intuitive way to create a data frame column by column creating empty one first, Then create your calm label at data tour than the next common able at data toe the next table at data towards pretty simple Um, in the next lesson here, we're gonna learn how to create a data frame from a local see SV file. So if I go to my home directory, uh, let me see what was the name of that? It was called City attempts. But if I go to my home directory and I looked for City Temps stat CSP, you can see here that I've created a CSTV file with my labels City, Monday, Tuesday, Wednesday, and then my rose, Houston, Dallas El Paso. So this is a local CS file. So to create a data friend from a local CSB file used the PD that read See SV method here and you pass your local CSC five. And this will create a data friend off your CSE five. You can see if I go back to see if we file it uses your your first role as your columns and then your 2nd 3rd and fourth row. 1st 2nd 3rd row as your data pretty simple. Read. See SV and your past. Osias refiled to it and create your data frame to create a data frame from an online cuz file. You just have to reference the Earl of that CIA zifa. So here I have a get hub you aro, in which I put the same city time see SV in my good hub. And then I passed that value to the read CSP, And it does exactly the same thing. So it treats it kind of like a local fob. Only you're referencing online, uh, fire. If I wanted to create a data frame from a Jason file, let me go to my city Temps. That Jason that is here and I'll include these files in the lesson. Resource is so you can have them as well. So here I have created a J son in which I have city. And then I have the data within city and notice that I have my indexes here. So if Houston, Dallas El Paso than Monday's data Tuesday's data and Wednesday's data So in here to read a local Jason file, use the PD that re Jason and passed the file name to it, and it will create your data frame from adjacent file. Pretty simple is one line of code, and you've created a data frame from a data set to do the same thing with a non lionization farm you do the same thing is a read CS three. You passed the u R l of Jason file to the Read that Jason Method, and it will create. You're a data fame from an online resource. Try these out. So we've learned 368 ways to create a data frame. Um, pretty simple in the Lexus, or you will learn how toe analyze the state of friends on. Remember, as usual, there are text instructions at the end of this video. Thanks 11. 10 Ways to Filter a DataFrame: Hello and welcome back to building Teach. In this started, we're gonna learn 10 techniques to filter and search at data frame. Let me hear the output first. So the 1st 1 the first thing we're gonna do is we're gonna create a data frame using a dictionary. This is one of the techniques we learned in the techniques to create a data frame. So it's It's basically a list of dictionaries, and this list of dictionaries will create for us a data frame, as you can see here it created for us three row for Khanum data frame off Texas City temperatures for three days. Now, if I wanted to filter columns from this data frame and I just I just wanted to select the city and one day, right on, we learned this in the data analysis technique. It's very simple. It's basically data frame your data frame name to square brackets, and then the columns that you want to select inside. Remember, the inner square brackets is a list, so it's a list off columns or can take one too many column names. So here I'm selecting City and Monday for this data frame and as you can see here, it's given me. It's returned back a new data frame with two columns. Columns that I select if I wanted to. Um, if I didn't want to filter columns, I want to feel toe rose and I want to filter rose based on values in a row Equalling ah value that I that I select. So in here I want only the rose where the city equals Houston. So the former is pretty simple. It's data frame, square brackets, state of frame square brackets, the column that you want to filter by. And then you use an operator here I'm using equal equal to equal the value. So I'm saying, here, give me all the data in data in my data frame for the column. City where the column. City equals Houston here. And as you can see here, this filter or this select gives me on Lee the Rose where City equals Houston. Now let's say I want only the Rose where city does not equal Houston. Same exact format as I did. Here's what's data frame square brackets, data frame, the condom you want and then not equal to Houston. So if I execute this it will give me all of the rows that not equal Houston. Pretty simple. Now let's say I want to select for values in a list. So I want to select for more than one value here. So I want Give me the columns in my data frame with a columns after Give me the rose in my data frame where the Columns City is in Houston or a passel. So the is in takes as a parameter a python list. Remember, a python list is created using the square brackets. And then here I have two values in the python Bliss, Houston and Al Paso. So this filter here gives me all of the rows in my data frame. Where City equal, Houston or El Paso years in a row. Paso. How about if I want all the rows in my data frame where city is not equal to Houston or a pass? So it's the same worry is here. The only difference is you have this little till the sign. At the very beginning, the tilting in front of the second data frame name makes it not so. This is not equals. So all the rows in my data frame with a condom. City is not equal to Houston or El Paso. And if you go here, you can see that it returns the other row. Data Dallas where it's where it's not Houston will pass. Remember this data from only has three rows Houston, Dallas in the past. So in this filter, it's giving me all of the roles where it's not Houston A passel, which the only role is Dallas? Um, the next one, um, is the data frame where the columns are not know. Now this one is going to give me, um, the, um, whole data frame, and that's because I probably should have put this above it. So that's let's move this up. Now what this does here, This is actually a pending a no value to my data friend. Right. As you can see here, I've appended the city of Galveston and I've put weather for Monday and Wednesday. Uh oh, I should have made that night. Do that up here again. Introduce that one again on Let's do that from here. Yeah, there is. So I have appended weather. So now the upend method is in the tutorials techniques to update data from. So you'll see that. What? You're getting a little bit of a, uh, preview here of that method. So basically what I'm saying here is a pen for me, an additional role. And I've added a null value. No value has to do with this numb pie. As MP n p n a. N is the way to create a no value in panda's. Aziz was here. I've put in a value. So if I have here, give me all of the rows in my data frame where Tuesday is not know it'll return on Lee. The data where Tuesday's not know, as you can see, a Houston Dallas, El Paso. But it won't return Galveston if I want it. All of the data in my data frame all the rows in my data from where Tuesday isn't? No. And I ran this. It would give me the Galveston data. As you can see here, remember, we created a no value here. We're looking for nominal values. It will return only the nominal values. And here we're looking for no values. It will return on Lee. The no values pretty easy. The next thing here that we want to cover is the worry. Method. Quarry method is a simple way to to write quarries for a data friend. Now I'm here. I'm saying give me all the rows where the city of with the city condom equals Houston. And if you see here, it gives me a city comical. Houston, One thing you do have to be very careful of when you're right inquiry is that if you're worry includes a string you have to use either single quotes outside and double quotes inside or double quotes outside and single quotes inside. So you could have written this like like this where it's single quotes inside. So in other words, you have to nest. Uh, your string inside your quotations so you could have done it with single quotes outside, double courts, insight or double quotes outside, single coach inside. That's that's something that can get a little tricky. But you have to just remember that if if you're quarrying of Al, you don't have to worry about the single quotes, double quotes, because in here, let's say here I'm saying Give me all the rows in my data frame where Tuesday equals 100 there's only one row in my data frame where Tuesday equals 100. Cool. The next thing that we want to look at is filtering by index. Now, remember, if you don't provide an index with data frame, it provides one for you, and it provides one in a numeric sequence starting a 012 So when you use this, I lock method, I lock is quarrying by index here. I'm saying, give me roll one. So remember, no one is actually the second row because it started zero and then one and then two. So here I'm saying give me row one. So I'm specifying roll one, Right? And, uh um, Row one in my data frame is Dallas Dallas 1 10 1999 That's exactly what it returned to Dallas 1 10 1999 Another thing you can do is the lock method. But when you use the lock method, you actually have to set the index yourself. All right, so you actually have to set, Let's say, here I've set the index to city. So now my index is not in America anymore. It's actually a label index, so I have to in order to use the lock method properly. You have to set your index to a label here. I've set the index with little notice that it changes the way the data from his rant. The original data frame had an American index, and then it had my condom. Rose. When you set the index, you're actually setting the index to be one of your columns. And here I've set the index of you Want to come? So now I can use the lock method properly here. I'm saying, give me the row where Theo Index is Houston or the label is Houston and you can see here it returns a 19 99 1900 which is the Houston row. Okay, so those are 10 techniques to filter and search data frame. Try them out. Of course. I have a copy of this notebook within this'll section to try it out on. I'll also paste the code at the end of the video. Thank you. 12. 10 Techniques to Filter/Search a DataFrame: Hello. And welcome back to building teach in this story. We're gonna go over 12 techniques toe update a data frame. So let's get started. The very first thing we're gonna do is we're gonna create a data frame on. We're gonna create a data frame using the list of lists method that we went over in the creating data frame. So basically, I have a list off lists. Rachel Square brackets are lists of lists, and basically, this is the row base approach. I'm adding a row. Per and this is something we went over in the creating data frames tutorial. So, as you can see here created a data frame with three rows and three or four columns pretty easy. So the first thing we're gonna do is we're gonna add a roto, a data frame using a dictionary and the upend method. And the a pen method is total. Do is it'll add a row at the very bottom of the data friend. So after the last populated, also add a roll down here. Now I'm gonna penned a dictionary. Remember? When you create a date, afraid muse in the dictionary. It takes the value pair right so it takes the value the key key value pair. It takes the key, and it uses that as the column, and it takes the value, and it uses that as the value right. So basically, here I am adding a row this time adding New York to my temperatures data frame. The ignore index basically creates a new line in here. And if this had been a ah, a data friend that we had already updated, it would wouldn't mess with the indexes. Which way we always set the ignore index A true when you're adding a dictionary, usually a pen and method. We can also use the A pen method to update a data frame using a Siri's. Now we have a whole section on Siri's following the data frame. But remember, the series is the one dimensional labeled array, so it's very similar to a dictionary s. So it's kind of a combination between a dictionary in a list. Some in here I've created a series of Boston with three temperatures, and then I have my labels, which are the condom. Mabel's sitting Monday, Tuesday and Wednesday. So I'm creating. I'm adding a Boston row, but this time instead of using a dictionary using a series. So data that pen the series name and then again, ignore index equals truth. And as you can see here have now and it Boston to the bottom of my data frame. Another thing you could do with the A pen method is you can at a data frame to another data from or append a data frame to another data frame. So here I am, creating my data frame row here, using again the lists of lists method, which is the same technique we use above. And then I am specifying the column. So this creates a data frame with one column. So let's just just really quickly take a look at that, right? Miami you can see here. It's a data frame with a single roll and it Now, I'm gonna use the pen method to take that Miami data frame, and I'm gonna add it to the bottom of my current data from As you can see here, Miami is now added to the bottom. Now, if you wanted to replace a value within a data frame, you would use the replace method, and the replace method takes as input the to replace value. So here I want to replace El Paso with a value Austin. So I'm gonna replace this El Paso value with awesome. And again the in place equals true means to make the change within this copy of the data frame. If I execute this now, instead of having a paso in my data frame, I have Austin. So remember, the replace method replaces values within your data friends. If I wanted to add a column to my data frame and with a column with the static value, just create a new column. So the way you created an economist data than the new condom name in square brackets and then the value that you want to set. So in here I'm adding a new column with a static value off Weather Channel as my source. So pretty easy. This is This is if you just wanted to have a static value. And again, we learned this in the data analysis section. This is this is review. So, in order to create a new column, use your data from name in square brackets at the new column name and then set the value another thing that's built into data frame are statistical measurements. So you can have I mean, Max median rains and all those types off measures at its your data from and it's really simple to use a eso in here. I'm gonna add three more columns to my data frame again data frame the new column name. And then these are built in to data friends. So if he just wanted to add the mean, you would say data that mean so it's gonna take the mean off the road number. Access one from the apply method is the Roe X zero is a column. So here we're adding the mean to the row here, So let's take a look at that. And as you can see here, it added the average temperature. So that's the mean, then the max temperature and then the median temperature to the state of rain. If I wanted to, um, update a value in a data frame using a formula. So let's say I want to increase the temperature of Wednesday by five, you would use the apply map. Now the apply map applies your function to all of the values in your data from so you have to be very, very careful when you use it. You actually have to target the column that you want to use. So if I if I did not put Wednesday in here, it would try to add five toe every single column in my data from but notice what I did here . It's the square back, a square bracket. So when you want to select a single column of data from so what this basically does is it creates a many data frame of just Wednesday's data, right, and it applies the Lambda functions. So this is adding five to my Wednesday column on Lee. So apply map. Remember again, the applying map function applies to all elements of the data from, So you have to very careful to make sure you select a subset of the data frame as a as a sub as a data frame itself. As you can see, it did here. So this adds toe all values in my data friend Andi. I could've used any any other dates. Let's try this year. So here's Tuesday. You can see here that now I've added 5 to 2 columns of my data frame and I could have done the same thing for Wednesday. But make sure that when you select your column that they are numeric and that the Lambda function will work on it. Now, the next thing we're gonna do is, um we're gonna use a apply map again function, which which applies to all elements of data. But this time I'm gonna add some true false logic in here. So in here I'm looking for the median temperature greater than 95. So using the apply map, I again remember, the apply map applies a function. Here is the land of function toe all of the elements of the data frame. But here I'm selecting just the median 10 just the medium time. So in here, that medium temp that apply map on, then I have a lambda function. So if the medium temp, which is X right, is greater than 95 than true else falls, as you can see here, the medium 10 piers greater than any fire foods. That's true. And here it sets to falls, Uh, a little complicated. But once you get the syntax correct, you learn how to use it. The map function is another way to update your data friend. Now the map function. What it does is it takes as input another dictionary or Siri's, another data structure that has both the current value and the new value in it right, and it maps the current value to the new value. So in here I'm adding a new column to my data friend, and that new column eyes the state and the state is based on the city. So in here I am saying that if the city is Houston than the state should be Texas right? If the city is Dallas, the station, Texas Cities, New York, the state should be in New York with cities Miami The state should be Florida. So what it basically does is it says it looks at this field, and then it looks at this dictionary, and it's now maps the value of one column to the new column based on this map. Okay, that's pretty simple. So again, the map function maps, all the values of the data from based on your input. Now again, you notice here that I am mapping a single column to that state dictionary. Okay? So again, we're gonna use the map function. But this time we're gonna use the map function to update a single field toe another value. So if you need it toe update a value in your data frame to be another value, you can also use the map function in here. I'm saying I want to correct the Weather Channel or Weather Channel input to be the Weather Channel. So I'm saying data source again. This time I'm referencing in existing common equals data Source that map source correct. So it's gonna get the values and source and it's gonna update it. Based on the dictionary that I have here. If you see here, it has updated the source to the Weather Channel. Another thing you can do is Thea Apply function. Now, the apply function applies a function based on the access to specify. Remember, we've done this in the data analysis. So the apply function toe, if you wanted to apply it to a column used the axis of zero if you wanted to apply to a role used the axis of one. So here we're gonna apply that function to a single row. So in here, I'm saying greater than 90 So what I'm saying is is that if the average temperature here's the average temperature is greater than 90 then return. True else returned false. And I have ah Landau Roseau row average temperature. So here, this is again applied to the road is gonna look at this rose average temperature and if it's greater than 90 is going to return true. And if it's less than 90 is gonna return. False to apply applies a function either on a column where access zero or on a row where access is one. So if you wanted to calculate a column using the apply within here, I'm gonna use the apply function with the axis of zero. So what I'm doing here is I'm selecting only Monday, Tuesday and Wednesday from the Data friend. And I want to apply the mean of Monday, Tuesday and Wednesday for the column. Right. So here's, uh, Monday, Monday, Tuesday and Wednesday, and I want to apply a function So the mean for this column, the mean for this condom and the mean for this calm and here it gives me the answer for the mean. So basically, I'm using numb pie to give me the main function, and I'm applying that function to the column. So that's again. This is the row based or the row, uh, application access one. And this is the column application access to. And I could do the same thing for the max. Right? Uh, NP Max would give me the daily data again for this For this data friend, apply the max. And here is giving me the max temperature for each role. Okay, um, hear what I'm gonna do is I'm gonna change the data type of a column. So let's say the look at the data types within this kind of remember, we looked at the attributes of data frames who used the D types. So if you wanted to change the data type off Monday, Tuesday and Wednesday from INT to float, you would use the as type function. Now, the ass type function will take your current data type, which is in and make it afloat. So if I run that you can see here that I have updated the state of France to instead of using INTs now it uses votes. So try those out. This was 12 techniques to updated Dave data frame and I'll have the code at the end of the video. And I also have this notebook a zey schimmel within your research folder. Thanks. 13. Using the ApplyMap Function: Hello and welcome back To build a teach in this tutorial, we're gonna go over a data frame technique using the apply map function on a data frame. Now, the apply map function applies a function to every single element in a data. Friend, let's go through an example here. I'm gonna create a data frame off foods, and if you notice all of the name to the foods are lower case. So if I wanted to upper case every single element in this data frame, I could use the applying matte function to apply the string that upper function toe all of the elements in the data frame, and I do it like so So here. I've created my foods DF data frame, as you see here and in the second cell here, I'm going to say foods DF that apply map. I'm going to use a lambda function arrested anonymous function with a variable of X, so X being all the elements for any one of the elements of the data frame to an upper and then the upper function. If I apply this shift enter, you can see that it has applied the upper function for the string for all of the strings inside of this data frame. Pretty simple. Remember, the apply map applies Ah, function to every single element of a data friend. No. How would we use the apply map function on a subset of elements in the data frame? Let me show you. So here I have my weather data from the one that we've been using another tutorials on. What I'm gonna do is I'm gonna apply the string upper to just a single common. The very first comin off the data frame. How would I do that? Simple. I would say weather DF that city because we're using city, we're gonna update the city. Come. So basically, I'm creating. I'm recreating the city calm, and then I'm gonna What I'm gonna do here is whether dot whether DF then double square brackets with city in the middle. So basically, I'm grabbing it as a subset, meaning that this now becomes the data frame that the applying map is working on that apply map that Lambda X lamb lamb on then X, that upper. And as you can see here, it worked on Onley one column of the entire data friend. So it worked on a subset of columns on the data front. Now let's say we wanted to do something with multiple columns, but not all of the comments of the data from Let's Say, I want to add 10 degrees to every single one of the weather's in my data frame. How would I do that? Very similar. I would first subset the comes that I want to update here. I want update Monday, Tuesday, Wednesday, then I would say, weather double square brackets. The columns. I want to update that. Apply map Lambda X X plus 10. So this will apply the X Plus 10 function to all of the elements that I have subset right here. And as you can see here, it's added 10 to the elements that I identified real simple. Try these out. I'll leave some code at the end of the video. And of course, I'll have the HTML version of this notebook as a resource, and I'll see you in the next video. Thank you 14. Using the Map Function: Hello and welcome back to building teach. In this tutorial, we're gonna learn how to use the map function on a data frame. Now the map function works on Siri's, but you can apply it to a data frame as well, by selecting a single column of the date of room and then applying the map to that column. So this give it a try here. So first I'm gonna create a data friend, gonna create a data frame off classes and subjects Here I have my subjects, teachers that teach that subject in the period where that is that that subject is taught, and what I want to do is I want to add a column to the data frame, which will assign a P credits based on the subject that I am taking. So in here I'll create a dictionary that will map the subject toe whether the AP credit is true or false, and then what I'll do is out. Call my class. I'll take my data frame and I'll create a new column called AP Credit. And then I'll take my data frame and I'll select the subject column, and I'll apply the map function using the A P credits dictionary. So let's run this and you'll see what happens. So if I run this, what it basically does is it uses this dictionary as a look up on the subject column. So it'll look up math, and it will know that math isn't AP credit course. So it'll map True to math. Look, a history you don't know. It's not a two credit course, my false except so pretty simple. It's a way to kind of like do a V look up in a Excel only using a dictionary now that was creating a new column. How about updating an existing column? So let's say your teachers for a particular subject have changed for a few of the courses. Where you would do is you would create a dictionary of your subjects and their teacher, and you can see here I've updated the science to Mr So Fear, and I'm updated to Spanish to Mr Bustamante here, and I basically now go and select the teacher column because I'm now updating the teacher column and then I select the subject column because of subject. Com is the look up column notice here. It's a subject teachers subject teacher and I apply the map function using the My Teachers dictionary. If I run this here, you will see that now Mr Rogers and Miss Gonzalez are the same. But Mr So Fear replaces Mr Singer and Mr Bustamante replaces Miss Bola. Pretty simple. So in this tutorial learn we learn how to use the map function on a column of a dictionary both to create a new column and to update a common on as years old will see this code at the end of this video. I'll also save the this notebook as a C amel and I'll see in the next video Thanks. 15. 6 Techniques to Export a DataFrame: Hello. Welcome back to building Teach in this historic unlearned various techniques to export data frame. So we learned how to update a data frame out of work with data frames. So one of the things will often have to do is you have to share the data from your analysis with either somebody else or with another system. So there are various ways to get the data from a data from an export it to another format. Here, we're going to learn how to export the data to a C S V to Excel, file to a python dictionary to Jason, file to a pickle file or for the to the clipboard for a copy and paste. Let's get started. So right now create a data frame using the list of list techniques or the role based approach. As you can see here I have my data frame with three roads and four column. So if I wanted to take this data frame and export, this data brain data frame to see is the file. It's very simple used to see SV method and then name your file. Don't you execute this. This will land in your home directory on. You can see here. I've actually done this once, but you can see here it it ran it and it populated a few seconds ago. The next thing we can do is we can export two. Excel to export Two Excel. You need this Excel writer method. The Excel writer method creates the Excel file. So you name your excel file using the excel brighter. And then you have an alias as writer and then you do the data frame to excel. You pass the writer to it and then you name your sheet. Turn here. When I run this, we'll do exactly the same thing. It will now land your excel file in your working directory. Another thing you can do is you can export your data to a python dictionary. To do that, you used to dicked method here on you can output your dictionary text as you can see here it out. Put this data frame to a dictionary and this would be more for passing a dictionary into maybe a python function for it to do other things. So it's more of a wave of sharing your data systemically. Obviously, python functions can also use data friends, but sometimes they'll require dictionaries. Another thing you could do is export your data to Jason Exported. Eight. It's Jason is very common in Web development, but it's also common in passing it as a type of data that another system can use. When you run to Jason again, it will produce a Jason file within your home directory. Another type of file that's commonly used in Python is the pickle file, and a pickle file is a way of saving objects in a way that that object can be copied exactly in another program. So it's a way of passing objects from one python program toe another. It's a way that Python recognizes so pickle data that PK l will do the same thing. It will add your file to a pickle file within your directory. And another thing you can do it. You can simply copy to the clipboard when you copied to the clipboard. It makes the data available for you to cut and paste so you can see here. I did control V, and I'm able to copy and paste the data from my clipboard. So those are the six ways to export a data frame and I'll see you the next video. Thank you 16. Create A Pandas Series: Hello and welcome back to building. Teach in this lesson. We're gonna cover creating a panda. Siri's if you remember from the last lesson, the Penda Siri's is a one dimensional labeled rate. What that means is that we have one dimension of data. So one condom of data and in another one of labels, right, even was calling index of labels. Um so to create a serious you have to use the serious constructor, which takes its input, your data on optional index and optional data type and the name of the serious Remember, Siri's could have a name in this section. We're gonna cover, creating empty Siri's create him Siri's from random values, creating a serious from a path python dictionary from a python list from a local and online CFC file and from a local and nine Jason file. So first, let's create and and he serious or Siri's with no data. Now, to use dependence library, you have to import the panels library. The way you do that, you write import pandas as PD, and here I have at the Ass PD is basically just an alias that allows me to write PD instead of writing out pandas on its the standards. It's away. Pandas is usually imported in pandas, uh, projects to import pandas, SPD, and then you have your valuable name here. First, Siri's equals PD that series and then the name of the Siri's. Now I've only put the name here because this is an empty SYRIZA has no data whatsoever. A press shift. Enter here. You can see I have a series. So Pandas has created a series with a name My empty Siris in a data type of float. That being the default data type for a Siri's now an empty Syria is kind of boring. Nothing really happens. The only time you created empty Syriza's when you populate that Siris in your program later . But let's start with some data. Let's say I don't have any data, so I want to generate some data so he having to generate some random values. Now there's a random integer generator in the number Pi library. Numb pie is commonly used with the Pandas library, so you'll see lots of projects where people import numb pie and pandas into their project. None pipe gives you the ability to create the arrays of data on generate random numbers and do statistical analysis. And Penders itself uses numb pie internally. But you can also use it external like I'm using here so important. Um, pie AS and P import pen is SPD have my variable name Random Siri's equals p d dot Siri's And here's my data and put data equals And here's my random number generator. So I have np dot random that rand in so random integer and then it has three parameters in it. It has the lower. So the floor of 80. So I want a number between 80 and then the ceiling 100 between 80 and 100 I want to produce three of them. So random number generator of values between 80 and 100 I want to produce three of them. Since I'm producing three points of data, I need three indices, three labels. So I have defined here three labels in my index parameter right here. So I've defined Houston Dallas in Austin. I'm gonna create a weather serious here. You can see here I have a Siri's with one column of data which is randomly generated by the num pie random that rand in generator, which has three temperatures, and I have three labels now. What happens if I remove the indices here? If I don't provide the labels well, pandas will just generate the labels for me, but it'll generate them in America, using in America sequence starting at zero, as you can see here. So you don't really have Teoh put the index, but it is more intuitive, and I think more useful when you do have an index cause then you can search by these labels . These labels are meaningful at that point, searching by an American Dixie's unless it's a small data sent, you really care. It's not that useful. But text labels are very useful because he reckoned, If I wanted to filter this Siri's, I know I want the Houston I want Dallas where I want Austin. I would just write that, and you will see that in the next tutorial. So let's zoom or the next one creating a series from a python dictionary. Now, if you're familiar with python, you'll know what a dictionary is. If you're not familiar with Python, I have a section within the python tutorials in this program that gives you an in depth introduction to dictionaries. But basically, dictionaries are a type of data container within python, Not in Pattison Python, which basically has a key value pair. So in here, If I wanted to create a series like of temperatures for cities in Texas, I would create a dictionary to create a dictionary. You need these curly braces here, you see here on you would need key value pairs. So Houston 99 Dallas 100 Austin 98 the key value pairs are separated by a colon, and each of those are separated by a comma. Right. So in here is my constructor to create the Siri's. So temperature equals PD that Siri's my data would have the this, uh, variable this variable here. So this is the name of the dictionary. So I've brought my dicked attempts, and then I'm named. I named the serious or name equals Texas attempts that have press shift enter here. It creates for me a Siri's from a dictionary and with the names, and it uses the keys as the indices you can see here, and it uses the values as the data. But it's a very convenient way to create a Siri's using the python dictionary on the next section here. We're gonna create a Siri's using a python list now to create a serious using a pipe, unless you need a list. Now list. If you're not familiar with the list and Python A Listers again, it's a container of data. But it's a container that only has values. As you can see here, I have set three temperatures the way to create a list as you need the square brackets here . And then you ever data between the square brackets or have a variable temps equals square brackets and the three temperatures and then close square bracket. And then I have another list of cities again within square brackets, you know, to outline the indices that I'm gonna use. So in here I have my serious constructor Temperature equals PD that Siri's temps as the data cities as my index and then the name of the Siri's pressure venture. Again, it produces similar type of the same. The same, uh, serious that you produce up there. Only it requires a few more steps right. You need now two lists, one for your data and one for your indices. whereas when you create it with a dictionary, you basically just need one container right here. So one dictionary No, to create a python after a panda. Siri's from a C S V file. I have I have uploaded a C S V file to my home directory on I believe that was called Where is it was called temps dot CS fee. So here is my temps, not CSP. So this is basically a C S V file that I have specified within my home directory so that I can now refer to it within my notebook. So it's got to be in the in a place within your Jupiter notebook that you can get to so I hear have important Penders SPD I have temperatures equals PD that read CSP So the read see SV function off pandas allows you to read as input CIA's v file. No, I make available to see if the file in the resource is section of this notebook, so you don't have to create it, but you can create one yourself. You will commonly commonly, you'll see as we files in analyses when using the pandas extent, because it's one of the easiest file types to distribute. Download from the Web or you can maybe have somebody produced them, or you produce them yourself at your job. Now to use the ritzy SV function to create a Siri's, you have to set this squeeze parameter as true. Now this is because the read See SV, typically, what the read CSB generates data frames. But if you provide the parameter as squeeze equals true, then it will. Instead of creating a data friend, it will create a series for you known here. I have set my labels as well right now, because when you read, CSB will not set the labels on dive. Set the index toe my labels right, so Cities goes Houston, Dallas in Austin And then I say temperatures dot index ical city. Now, if I execute this, it will create my Siri's. So let's say, if I didn't that's comment this out, Uh, and then I'm gonna run this again. You can see that if I don't specify my labels, it will order. Generate your index a key. So that's That's the reason I created a list with the labels, and I've set the index to those labels. City you can see here If you wanted to create a, uh, Siri's from an online CIA's before it's exactly the same steps. The only difference is that instead of referencing the online, I mean the local CIA's reef Are you referenced the online CSE false? I've I've put the same CS we file showed earlier into my get hub repository and I'm reading that same you are that you are l into the read see SV function. And again, I used to squeeze equals true and I set my indices and you could see it produces the same thing here I'm creating a series from a Jason Fall. So again I've created a Jason file here of temperatures. This is in Jason format. I uploaded it to my working folder and I'm referencing no file within my working folder. So to read a Jason file into a Siri's, you have to use the read Jason Method here. So I've imported pandas SPD. I have a variable temps. Jason equals P. D. That read Jason. Now the re Jason again is exactly the same as the read CSB. It, by default, produces a data frame. So you have to run this squeeze method here. Siri's Jason equals temps. Jason that squeeze and then run this here and you can see it. It runs, and it produces for you I a Siri's. If you don't. If you don't specify the squeeze. If you don't specify the squeeze. And let's say I just want to read, uh, so Tim's Jason it will produce a data frame. Now, this is the data from this is not a Siri's. Um, I can I can prove that here, uh, temps attempts within s Jason you got I see here it says that this is, in fact, a data frame and not a Jason. If I were to write seriously, will turned false. As you can see, this is a night of Siri's. But if I do the squeeze method here and i a reference theories, Jason, it will tell you that this, uh, this object is in fact, a Siri's Now to create a series from an online Jason file. You say you follow exactly the same procedure. The only difference is, instead of referencing your local Jason file, you will reference your Jason you are l. And then the rest of the steps are exactly the same again. I'll make both the CSP and the Jason file available to you in the resource is section of this tutorial. And give these a try. And it's quite a bit to learn right now. But these are the various ways to create a serious from different data. Uh, containers, I guess you could say, um, give this a try. Practice the money notebook, and I'll see in the next video. Thanks. 17. Analyze a Pandas Series: Hello and welcome back to building teach. In this tutorial, we're gonna learn how to analyze a panda Siris on the last tutorial, learn how to create one. And then dysentery had analyzed Ah, Siri's now to analyze the Siri's is, ah, a couple of attributes and a couple of methods that you can use first of all, what? We're gonna go ahead and we're going to create a series to create a Siri's again. You import the pandas library here? I'm important Numb pie Library, because I'm gonna put a a not a number in no value within the data off this Siri's. Now this theories is a series of grades a za can see here we've got grades. I name the Siri's history grades and I set the index to a set of students and notice that the panda Siri's allows you to have duplicate keys here so you can have multiple grades per name. So when I when I run this, you can see I have a list of about. I think it's 12345678 10 10 names and the last one being a no value as you're going to see here now to analyze a Siri's first, Let's say you forgot what with this Siri's Woz, and you happened to have a name for it. So if you want to get the name of the Siri's use, the name attributes. So in here have my grade. Siri's grades, that name and it will tell you the names. Attributes. Let me just clear the output, so see them fresh. Here you have the names. Attributes Do you want the row account of the Siri's used size attributes of grade start size? You can see here we have 10 items in this series. If you wanna know the data type used in the Siri's used a D type attributes grades that D type, you can see that this all of the grades within this Siris are floats. If you want statistics on your Siri's, use the describe method here, so grades that describe and it'll tell you your account it will tell you your mean your standard deviation, your minimum, your 25th percentile, 50th percentile, 75th percentile and your max. So these are all the various statistics that you can run on. The Siri's described gives you all of them puts all of them. If you just want the mean, you would use the mean function praise that mean, and we'll tell you mean similar to what you have described. If you wanted to just pull the first few rows just so you can see what's in the Siri's. You was the head function till grades that had head will give you the 1st 5 rose if you don't put a value inside the parentheses. If you put a value inside the parentheses, it'll it'll give you the whatever value our top to top 10 top whatever you want. Eso here the top two rows or the first not top to the 1st 2 rows if you want the last five rows used tail function. See here you've got the tail function. I want the last row, whose tale with a value of how many you want toe returns here. I'm returning the last rule just one right. If you wanted to sort the values in your Siri's, use the sort values function, so grades that sort value. This will sort your values valid within the Siri's. If you want to sort by index or sort by name, use a sort index function, and you can see here it's sorted the names within the Siri's. So try these out these air quick ways to you analyze the series to for you to peek into what's in the series and and start your analysis. Try this out. And, as usual, there are text instructions at the end of this video. Thank 18. Search and Filter a Pandas Series: Hello and welcome back to building teach. In this tutorial, we're going to learn how to select or filter data from a series we're gonna start with. Head and tail are function was recovered in the last tutorial. So it's a quick review Head and Taylor used very often. When you just want a load and look at your data real quickly, then we're gonna look at selecting and filtering by using the index using the I lock function. Then when you're gonna we're gonna look at the selective filter using the label use in the lock function. Then we're going to select a filter by value using operators, selecting filter by value, using the wear function and then using that is in function. And then we're also going to search and filter by value, using the lock on returning bull Boolean results. We're going to search by values in the lock and turn rose with values in them. So let's get started. So first, let's create a Siri's. So we're going back to the same greats a Siri's that we created in the last tutorial. Basically, I imported pandas. I called the PD that Siri's constructor here I have a data set here of grades have named the series history grades and I've included an index of student names in here You can see here. So as a review from the last tutorial, if you want the 1st 5 rows of a Siri's used the head function. So grades that head in return the 1st 5 rose. If you want to limit how many it returns or you want to set how Maney returns, you can just put a put a number inside the parentheses and will return that number of roles . So if I want three rows, I used the head and I get three rows. I noticed I didn't put the tail in here, So let's put the tail in here. Great stock tail. We'll give you the last five rolls on a great start tail, uh, to let's say give me the last two roads you can see here last two rows. John and Jane. Okay, so the next thing we're gonna cover filtering by index, remember the index. Here are the name our names, right? Actually, three index years is the actual numeric values. Starting at zero eso. The first position would be zero. So grades that I lock zero will give you the first value. Just 97 is. You can see here if you wanna use. I like to return a list of indexes Here Have the first, the second and the fourth right index 035 It'll it'll return those if you just pass a list of indexes. So this is searching by index, not by label index, which is the numeric representation of the order within the Siri's, Um, And within I lock, you can also use slice notation if you remember from the strange tutorial or the list tutorial. Slice rotation has these two positions within the square brackets separated by a colon. So if you input the first position, it will be the starting point, and the last position will be the end point before the last value. So up to but not including three. So in here, I say, give me all of the positions up to, but not including three starting at zero in here, I'm saying, Started three and give me the rest of the positions at the end. So if you don't specify the last our value off a slice, it gives everything towards the end and in here, I'm saying, started to but end before four. If I click on these, you can see that it returns these values using slice notation. So again I lack is to search by index by the numeric representation of the order within. The Siri's lock is used to search by label. Remember, this right here is the label, right? The index would be 012345 all the way up to nine in here. So if you wanted to search by label, use the lock. So if I want all the grades for Henry, I'm telling it grades that Locke Henry and it will return all the grades within the serious that have the name Henry. If I want all the greats for Henry and Jane, put the values within the list and it will return a low values between four. Henry and Jane. Remember, Lock is to search my label on. You can specify a list of names just like you can specify a list of indexes in the eye lock . Another way to serve a Siri's is using operators eso equal to greater than less than and all those that we learned in the python tutorials. So in here it's a different way of writing it, right? So I'm here. I'm saying give me all the grades equal to 100. So and what I need to do is I need to say, grades, square brackets, grades equal, equal 100. And this will give me the values within the series that are equal 200. You can see that Jane and John both got 100. If I wanted to say grades less than 100 I would say graze square bracket grades less than 100 on closing square bracket. And it will give me all the grades less than 100. And if I wanted all the grades greater than 80 but less than 90 I would use grade square bracket and then parentheses. Grades greater than 80 and parentheses, grades less than 90 on closed apprentices and close square brackets. And this will give me all the grades greater than 80 and less than 90. So this is a, ah, a way of filtering or selecting data within a Siri's using operators. You can also use the the wear function to do very similar things. So grades where grades less than 90. Uh, it will give me all the grades with us in any but the the thing about the where is that It returns all the data and it gives, you know, values for anything that is not less than 90. So the two to stop it from returning no values, you would upend the drop in a function to the end of your where, uh, statement here. And what that will do is it will just drop all the no values and will return to you. Only the values that meet this criteria the is in function is another way to to filter data within a Siri's. So, basically, you say grace where bracket grades is in, and then you provide a list of values that you want to return. And here I'm saying, give me all the grades in that either 199. Give me all the grace of 100 uh, and you can also within the lock functions are well appear. We use the lock function to just use the label, too, to filter the data. But you can also use an operator in the lock. A such such as this right greater than 90 and it will return a Boolean representation of the data. So give me all the grades for Henry than a greater than 90 and here will tell me that two grades are passed. The test of really the 90 and one grade doesn't. If I want to just return, um, the values, right. If I don't want to just return the values, I would do this in two steps. First, I would filter the grades. Let me just cut this, and so you can see what happens. First, I would filter the grades for Henry. And here you can see these other grades for Henry. And then I would create a new series where the grades for Henry are greater than 90. And I'm gonna drop the n a and here is gonna just is gonna return the values. So instead of returning the true falls by doing it in two steps in here and then searching the new series that I I have filtered here Well, give me the values. That's ah little neat trick to be able to use the wear function on the local function to return values. So give this a try. Try the head to tail the I lock to search for by index. The locks asserts by label search with operators are aware functions which is in use a locked Turnbull and use a lock to return values gives to try. And as usual, there are text instructions at the end of this video. Thank you. 19. Update a Pandas Series: Hello and welcome back to Bill and teach in this story. We're going to learn how to update a panda. Siri's, uh, so we're gonna learn how to add items to the Siri's. Using the a pendant function, I had to replace items in the Siri's using the replace function. We're gonna learn how toe remove items from receivers using the drop function, how to fill no values using the fill in a function and had an update of value by sea in a Siri's by index and also using the update function. Okay, let's get into it. So the first time doing here is I'm creating a pandas theories. I've imported Pandas PD and None pie as MP numb pie so that we can have no values and the Siri's so they didn't pass it. Orioles. So here have a grade. Siri's grades equals p d dot Siri's. I have my data, which I have four data points 97 9300 and no value have set the name to the Siri's as history grades and I have set for indexes here. Henry, John Jane and Pee Wee. If I press shift enter, you can see that I've created. My SYRIZA has a name as a type and has the four values in here. So let's say I wanted to add two more students to my history. Grades serious. So in here. In order to add uh, values to Siri's, you can use the append function and the A pen takes as input another Siri's. So you're adding a serious toe, Another Syria tour of the current Siri's. So here I have created the new Siri's additional grades equals PD that Siri's have to graze 98 99 4 Peter and Paul and then I have a creating a new Siri's out of that. So no, Siri's equals grades to the original Siri's upend additional grade. So I'm a pending the additional grades. The new grade Siri's And, as you can see here, Peter and Paul, with their 98 99 end up at the end of our Siri's. If I wanted to replace values in a Siri's, let's say in here I want to replace the 93 within 95 I want to replace the 99 with 100 so the in order to do that, I would use the replace function and I would specify the to replace. So I'm replacing 93 and 99 with the value 95 and 100 and I'm replacing them in place in place means, uh, don't do it in a copy. Do it inside of the current Siri's. So as you can see here, my 93 is now 95 my 99 is now 100. If I wanted to remove items from the Siri's, let's say I want to drop Peewee from the grades. Xperia doesn't have a grade in here, all right? Actually, I mean, let me move this down, because that's gonna get in the way of this one. So let's not remove P. We just yet. Let's that's first replace his an A grade with something. So sometimes in your in your data set, you're gonna have no valid in this data that we created the data set with no value if you wanted to have a default. So let's say anybody who didn't pass the test here and doesn't have a great we'll get a 70 by default. So to replace no values used to fill and a function so fill in a will replace your pee wee of no or not a number with peewee of 70. So people now has a 70 because I filled the no value fill in a with a value of 70 as you can see here. So now let's remove people. So we want to remove a grade. Let's say we want to remove peewee from our list here. So to remove an item from a Siri's used to drop function and you specify the label, uh, that you want to remove. So I'm here. I'm saying new grades that drop Pee wee's on dropping peewee from the function from the Siri's. As you can see here, there is no longer on that list to replace values. In a serious you can replace values by indexes. That's one way to do it. Um, so in here I have blue grades, my first value. I want to make it 100 and my second value on making hundreds. I'm doing as you can see. I'm doing it by index. Here you see here if I run this, I've replaced the first and the second by 100. If you wanted to replace multiple values again by index, you would use the same format, but instead you will pass a list of indexes and a list of value. So here I'm replacing the first, second and third values, each with 90. You can see here. There have been updated another way to update a Siri's issues the update method. Now the update method takes as input another Siri's Samir in here. I'm creating a series of 101 100 I've created labels for them. So Henry and James So what it with update does is it aligns the values of the new Siri's with the values of the old Siri's by index. So here I'm specified, specifying that Henry should get 100 and Jane should get 100. So Henry and Jane to get hundreds. If I run this, you can see now. Henry and Jane both have 100 Um, so the way the update method works well, let's let's create a create an empty It's created new series of just americ indexes, right? So in here I've created a Siri's with three values 103 104 100 and if I want to update that , Siri's toe have 507 100 At the first and third respective indexes, you would use the update method. You would specify the values and you would specify the indexes. So, as you can see here, the first and the third were updated when the same thing The only difference is here. I'm using the American nexus here. I'm using the actual label as the index instead, use either or right you zero r one or r the American indexes. Give those a try. I tried the depend function. Try the replace function. Try drop function. Fill your no values with Phil in a on try to use the update function to update your Siris on a Z. Usual there text instructions at the end of this video. Thank you. 20. Intro To Python: HelloWorld: Hello and welcome back to building. Teach in this section will be covered in the World Project. So how the world is the traditional first program for students during new programming. Language on in this tutorial will be creating the Hello World, and you'll see how simple it is to write a hello world program within Python. But before we get started, it's Let's go and do a quick overview of the Jupiter notebook so that you don't get stuck in case you you skipped the section of the Super Notebook. Let's go over real quick here. Now there's two main types of cells within the Super notebook. The first type of cell is this mark down cell you can see here. This cell up here is a markdown cell. It's used to display text in different formats as well as images. It's usually used to describe the contents of the notebook or the contents of the cell below the mark down, so on, you can tell you in a marked on cell, if you double click on it, you'll see that it doesn't have this in prefix before the cell, and you can also tell because the markdown item is highlighted in the this drop down markdown cells take markdown language, which in here I have a few examples of markdown language. Have a header which is a header one which is created by using a single, uh, number symbol Here, have a head or three which requires three number symbols absolute basic texts which you just start typing your text on. And I have some bullets. Bullets are created by using the hyphen and some space and then the text you want to display to execute within the markdown cell and even in the cold. So which is the other type myself? All you have to do is press shift and enter. And you can see here that the Jupiter notebook has now formatted the text or the mark down that you specified within your mark down. So the second type of cell that we have in the Jupiter notebook is a code. So you can tell it to Kotze because they have. It'll have code highlighted in the drop down, as well as this input prefix on this right here is a coats up. So the hello world program to write hello world or to print output Ah, hello world. All you have to do is execute the print function, been open parentheses and close parentheses with some Texan between Come in here. I have hello world as the Texan between Now to execute this code simply right, simply click on shift, enter and you'll see that the head of world is output at the bottom of the South. You'll also notice some other text within this cell. The other sex is the comment is a single line comment, and in here a single line comment is created by using the number symbol and then writing. Some text comments are not executed by the notebook. They are ignored, so there may be there to help the programmer describe what they're doing or remind them of what they were doing when they wrote the program or for some brief instructions and then execute the pregnant. Also to write a comment. Ah, single and comment. You just used the number symbol and then you write some text. If you need larger comments, multi line comments, you wouldn't do a multi line comment using three single quotes at the beginning of a text and three single quotes at the end of the text. Now give these a try. Give them mark down a try. Try to create a header 102 103 104. Try to create some text, maybe some bullets and then try the hello World program. Simply print open parentheses. Your text close parentheses to execute a south remember shift. Enter Onda. Also, try some multi line comments and a Z You can see here. Give these a try. As always, they'll be text instructions at the end of this story. Thank you. 21. Intro to Python: Keywords: Hello and welcome back to building teach. In this tutorial, we're gonna go over key words. Now keywords are reserved words within a programming language. Every single programming language that you learn will have these reserved words on their reserve because you cannot use them for any other purpose, like you can't use them in variables. You can't use them and function names. They're just words that are set so that the compiler of the or the Interpreter, depending the type of language, can read them, and they will know what to do. So to view the list of keywords using the Python notebook, it's pretty simple. Just right. Help open parentheses, Keywords close parentheses for a shift. Enter, and it'll give you the list of the 33 keywords that are reserved in the python language. Um, very important on, and you will learn some of these as we go through the lessons. It's very important because the next chapter will be covering covering, creating variables on you'll know not to use thes words when creating variables. Another way, you condone tell if something is a key word. It it'll be colored. You can see here that if is colored in green in this color and green. But if I write, you know car, it will be in black letters. You can tell a key worthy, at least the Jupiter. No pickle will tell you if something is a key word, because it will cover it in green. So that's another way to tell if you're using keyword by mistake, inside of your variable or functioning, which we'll go, we'll go over creating variables. Next, give that a try on. We'll see you in the next tutorial. 22. Intro to Pyton: Variables and Datatypes: Hello and welcome back to building teach in this lesson, we're gonna cover creating variables. Now, all programming language store data in variables and variables are really just labels that store that data in Python python is a dynamically typed language meaning that the variable is not tied to a particular type. There are strongly typed language is where the variable is tied to the data type, but in python it's not. So you can have variable X start off as an int and then you can change extra string. You can change XTO a flow, etcetera. Now there are four main types of data types within the python language. The 1st 1 is interred yours now into jours our numbers without decimals. That can be any size and they're constrained only by the memory in your computer. So in here you can see in this table uninterested. It could be 1 100,000 or one with whatever 100 zeroes if if you want, it's just limited by the memory in your computer. Floating point numbers are numbers that require a decimal point, and you can also use scientific no pit notation so you can use for each of the five, which is the same thing as 40,000. Uh, so you have integers, floating points. Boolean are true and false. They only hold two values true or false. And then strings are the fourth type. These are sequence of characters or letters right there, delimit that that can be created using a single quote or a double quote never makes you can single double you Can I do all single quote, opening, closing or all. Double quote, double quote, opening, closing. So to create an in Israel. Simple. Here we have a valuable name. X X equals 100 here I'm printing the X. You can see here that it prints 100 and here I'm using the type function. The type function will read the variable and we'll tell you what data type of it. So you can see here I've created an end variable of X on here. I'm creating afloat notice. I'm using the same variable name. Since it's dynamically typed, I can just reuse the variable eso here I have a float. X equals 100.23 printing the X You can see here, and I'm taking the tape and you can see, it's a type of float. The next one is a Boolean again. A Boolean holds to one of two values at the true or false. Here I'm creating a Boolean. A bullion of true so X equals true printing. True and I'm getting the type, which is a Boolean, and the last one here is a string again. It's the sequence of characters, characters also letters. It could be numbers, too. Eso sequence of characters and they are created using the single quote or double courts. You notice here I used double quotes, so X equals Hello, I'm printing Hello and I'm using type to read What type of data type the viable is here to string now You can also cast meaning you can change the value of a variable using the's functions. So if you had a float or a string and you wanted to cast it or convert it to an end, you would use the int function here. So here I've created a float value of X equals 1.5, and then I I'm setting Why, which is another variable, equal toe end X meaning of cast that float toe into I'm printing out why, and I'm getting the data type and notice that this was a float of 1.5. When you cast it, you lose that decimal point. So now it converted it to one right, and it's a one of type int. So why is of type? And because I have cast it here, you can also cast to float from an into her string. Here, I've created a variable x of one and which is a type of int, right? And I'm using the float function. I set the variable. Why? To float X right? I'm printing. Why now? It adds a decimal point in the zero, and that data type is now float. And I can also do the same thing, which strings eso I can. I can cast an EMT or float to a string. Sometimes you have to take a string on, be taken into afloat and converted to string toe output. It like to a browser. I'll put it to our your application and something that's very common here. I've created a float X 1.5. I've cast that float to a string. I'm printing that string, and I'm getting the type of straining to see here that it's a type of strength. Give these a try. Try creating immense floats, bulletins and strings, and try converting these over toe each other. Right. Even you can convert a string of photo end. Oh, our and inter string toe a flow or an inter float to a string so you can move back and forth from all of these data types. Give this a try. And, as usual, you have Texan structures at the end of this video. Thanks. 23. Intro to Python: Math in Python: Hello and welcome back to building. Teach in this lesson. We're gonna cover math calculations and python. Now, computer math calculations is very common in all programming language and languages, especially in python, which is used a lot in data signs and in finance and accounting software. Um, so here, I'll show you how to do simple math in the last, um, the tutorial we covered creating variable. So here I'm creating two variables X and Y, and I'm gonna do addition using operators. So the operator for addition is the plus symbol. Just wasn't regular math. So here have a valuable some equals X plus y. And then I'm printing the some. So seven plus five equals 12 for subtraction. The operator is the minus sign, just like in regular math. So have two variables X and y. So it's 10 minus five and the difference equals five. You can see here Multiplication theme. Multiplication symbol is the asterisks symbol you could see here. Eso have X and y four times three And that product eyes 12 4 times three is 12 to the division. Real simple. You just used a forward slash eso Here I have X and y 20 divided by five on the, uh, division, uh, answer is 4 20 divided by five is four exponential Israel Simple used to ask traces so that one Astros is multiplication to Astra's is exponential. So here have five to the power of to you can see here five to the power of two is five times five, which was 25. Uh, then I have remainder or the module ISS function here. This function gives you a remainder of a division, so I have here 10 divided by three. So 10 divided by three is nine remainder one, and you can see that the remainder here is one. This is really useful for like judging. If something is odd or even if it's even, it will not have a remainder. If it's odd, it will have remainder square root calculation to do square roots. You have to bring in the math library, and you would do math that square root of X so the square root of four is too. So give those to try and, as usual, will have text instructions at the end of this tutorial. Thank you 24. Intro to Python: Strings in Python: Okay, This story we're gonna be working with Strange. On the last tutorial, we went over variables and strings were one of the data sites that variables can hold. I remember to create a string. All you need is a variable equals. And then your string within quotation marks you have of the double quotes or single quotes , As you can see here have created a string called My String with the string value off computer output that you can see that you have computer. Now, the way python handles strings and it actually creates thes positions, uh, within memory on each position has an index eso This computer is an eight letter string on the index. All indexes started zero. So the index it will be from 0 to 7. So 0 to 7 means as eight characters, zero being the first character and seven being the last character. So if we wanted to output the first character of a string, we would use this notation right here. So I have your my string square bracket zero. If I execute this, you can see it returns. The first character of that string If we wanted the last character of this string. Remember, it's an eight character string in the last position is seven. So if you wanted the last character, that string, we would say in my string square bracket seven, you could see it outputs the last character of that string. If we didn't know the length of the string, we could use this notation here. We could use the value of negative one. Negative one would also return the last character of the string without you having to know the length of a string of the street. If you wanted to find out the length of the string, all you have to do is use the length L E N functions Len function so L L e N parentheses and then your variable. You can see here that my string, which is computer, is an eight character strings. And remember that strings start at index zero. So the first character zero on the last character, iss seven in an eight character strength. Another useful thing that you could do in python iss slice notation, slice notation is is a way to get sub string so strings within a string. So if you have a phrase and you don't want all the words in the phrase You just want a certain section of that string. You would use string slice notation. Now, the way slice notation works is, you know, is very similar to the way we did single characters. You use the square bracket, but the difference is you have now to values separated by a colon. So your first value would be the starting position and your last value would be your ending before position so up to this value but do not include this value. In other words or last position plus one is another way to think of it. Right. So here I'm gonna create a string with the phrase, uh, the quick brown fox now in memory or within python it would it would create an 18 character string, right? Because, remember, spaces are also, uh, indexed are also considered characters within that string. So in here, position zero is T from the and position 18 is X from X. So if we wanted the first three characters of the string so from position zero up to, but not including position three. So position 01 and two, we would use the slice rotation. My string square bracket. Zero Colin three. So include started zero, but include everything up until before three. So 0123 you can see here up until but before three. So position 39 Inclusive. So which would be the last position? Plus one If we wanted Teoh, Let's say get the the character starting at Position 10 here. Right, Starting position 10. We would say the starting point of your slice would be 10. So in here it would start with 10 so you would expect it to return Brown Fox. And, as you can see, starting it was in 10. It returns Brown Fox, if you want it everything up until before position 10. So from 0 to 9 you would use the notation like this so you will leave the first position blank, and you will leave the second position as 10 so up to, but not including Position 10. You can see here that it returns quick, including the space after the quick right. So that's That's one very initial way, and it's a very common thing to do. Let's say you have some type of I D or some type of description and you just want a you know, a product identifier of some type. You would you slice notation. So remember the slice rotation is your variable square bracket, the starting position and the ending before position or the last position plus one to remember that the last position is not included. Another useful thing you could do in strings is concocted Nation. So you want to combine two strings? So here I have two strings greeting being hello and name equals John. So if I wanted to output Hello, John, all I would have to do is add them. Greeting plus name. So greeting being hello with space and name being John. So Hello, John. So contaminating strings and pythons. Very simple. All you need is the plus sign. Another useful thing within python is if you want to see if a character contains absolute If a string contains a specific character, you would use the in keyword. So here I have this random string a 43 b 23 c 83 and I want to see if be exists in this strength. So all I would say is be in your valuable name so and it would return True if it exists So being obviously is in this string true if it exists and false. If it doesn't so let's say another one, right. I want to see if 23 c is in this string on on it ISS right. You can see it. 23 sea is in the street. And if I if I put a character that's not in the string, I would say zn sample and it would return false if it doesn't exist in the strings. That's another very useful function. Our keyword. Actually, another thing you can do in Python is make all of the characters in your string upper case . So to make all of the characters in your string upper case, you would use the upper function here. Here you can see you have the string to be or not to be all in lower case and I want to make it uppercase. Right. So I used my string that upper you can see it returns the upper case. If I wanted to make all of the characters in my stream lower case. Very similar thing right here. I have an upper case string and I want to make it lower. All you do is that lower and it will make a lot off the characters in your string lower. If I wanted to capitalize the first letter of my string, I would use the capitalized function. So here have whether it is nobler in the mind to suffer on. I want to capitalize The very first letter the capitalized function will capitalize the first letter of strength. So I kind of like in a sentence from the first letter of the stream. If you want to use title case, the title case will will uppercase on Lee the first letters of every word in the string. So only uppercase the first letter. Um oh, I'm just a prince. Oh, what did I do here? There it is. Sorry, I messed that one up. Put. All you have to do is it's the title function title function. So the title function will uppercase the first letter of every word in your string. So similar to a title in a book. Uh, another thing you were that's common in strings is you wanna check if your string is a number, so is numeric. Is the wayto to do that so that there is numeric functions. So here I have a string and it's all in America. It's all numbers and I'm testing whether that string is America. And here you can see that it is so return. True if it wasn't right here is a a string with a mix of of letters and numbers are checking It is in America and you can see that it is false Another thing that you commonly do and strings It was called Z Phil. So let's say you haven't identified an I d and your I d has to be eight digits long. But you have I ds of 101 Right. So you need to pad it with five characters. So let's say, here you have you require an eight digit car on eight digit string, but you only have five digits. You can see here that by using the Z, fill it now pads. This number are the string with three zeros and I have another one here with three characters and now I have it padded with five zero. So z fellow pad your string so that it always fits a certain life, which is very useful when you're working with with ideas or required types that require certain length, so try out of those out. These are very usefully, and there's a lot of stuff in this chapter, so try out creating a string, getting the first and last letters or even the middle letters of a string getting the length of the string using sliced notation to get sub strings. So try these out. Get used to the syntax. Remember that it's the starting point and the ending before positions with the nine inclusive end or the end plus one is another way to think of it. Way also learned how to captain eight strings practice contaminating strings. Practice checking if a string contains a character letter using the in keyword practice making strings. Uppercase making strings. Lower case. Capitalizing the first letter of the string using title case. Checking if a string is numeric or not in America and patting the string. These are all very common things you do in programming in Python and also in Penda as so practice and Azaz Usual. There are text instructions at the end of this 25. Intro to Python: Output Strings using .format(): Hello and welcome back to the teach in this story would be going over the format function of the string object in python. Now, the format function is a more elegant way to output strings that allows it up with a string with multiple substitution Z on value formats. So the input of the former function could be interred. Your float, a string variable objects, etcetera on the return type will be a formatted string. Now, the typical way in more traditional programming languages to print uh, variables out would be to use the print function, and then so can can eight your your string variable to whatever strings you have in there. So use this plus, and then you're out putting valuable. You've seen do that quite a few tutorials, mainly because I have experience in other languages. And that's just something I'm used to eso in here. If I wanted to output prints. Hello, Henry. I would just say print. Then I would hard quotas drink hello, Plus my variable Henry, which is nothing wrong with doing it, But it can get tedious, and it could get worded. So, of course, Python found a more elegant way off out putting strings, which is this format function here. So in here, I do exactly the same thing. I have a variable with my name and then print Hello. And then you have these curly brackets, and then you close the string dot format and then you substitute for whatever value is in would want in the curly brackets to in here, you can see it's hello. And then my name on the beauty of this is I mean, it doesn't seem so elegant here, but you will see in this next example how elegant they can get, because again, you're doing everything in minimal lines of code. So in here I have imported this this so I can get the version of python I'm using have important the date, time and date so I could get today's date. And I have here for variables. I have a strap two strings. I have a now output of the system versions for chaplains to be a string also, and I have a date in here. So today's date and you can see I have half here a formatted string output. So hello. And then it I'm substituting for the first curly bracket My name you are using for the second curly bracket. The language today is for the 3rd 1 I have a date and then the This is version. So the version of python that music and you can see in very few lines of code you have a more elegant way toe output this strength. Imagine if I was using concatenation, I would have to say hello. I would have to close a string plus name plus and then a single call it etcetera and it would get pretty ugly pretty fast. So the format function gives you a more elegant way of out putting formatted string. So give those try. Try using those and stay that contamination in your code. And as usual, there are text instructions at the end of this video. 26. Intro to Python: Using the Standard Lib: Hello and welcome back to building Teach in this lesson, we will be covering, importing and using python standard library modules that python standard library modules are modules that are built into python, meaning you don't have to install them using installers like PIP or conduct for Anaconda. Uh, the built in all you have to do is imported into your program, and you have very powerful modules at your fingertips. In this lesson, we will cover three of the standard LABRIE modules, cover the math module, the random module and the regular expressions module R E module. Well, let's get into it. It's absolute fun. So the very first thing we're gonna uses the math module. So we saw a little bit of the math monster where we're doing the, uh, math operations and one of the prior tutorials. So in here, one of the powerful things in the math model is that it has these constants. Ah, all of you familiar with geometry. You're familiar with pie 3.14 It says right sector, etcetera. Well, in python, you don't have to remember the eccentric sector, except you just have to use the constant, so you would import math. And here I have a variable of pie, and that was a pi equals math, that pie. You can do the same thing with Mueller's number. R E. So I have e equals math that if you execute this, you can see that. Now you have pie 3.14159 etcetera, and you have the euro number 2.718 to 8. So pretty simple. You don't have to have these as variables that you defined yourself. Just use the constants built into the math module. Another thing you can do with the math module is converting floating point numbers. So this is like rounding floating point numbers. One of the methods that are in the math module is this trunk or truncate function. This one basically just cuts out the digits after the decimal point. The floor method. It takes the largest injured or less than the number that you provided, and the seal method takes the integer greater than the number you provided. So she execute this. The trunk basically removes the three digits after the decimal, the floor round it down to the whole number and the seal rounds it up to the whole number. Um, from so basically here it's 80 99 90. Pretty simple, very useful. Um, another good messages in the mass module is this f absolute? So if you're working with absolute numbers and you want the absolute number, you would just do math that f a B s and the number you want to get the absolute value. So here I have a variable of negative one or two and I'm taking the absolute value of negative one or two becomes one or two. Another cool tool within the math module is Theis exponents. Toe power here, I'm gonna do to to the power off. Four math that pau on then the number and then the exponents two to the power of four, which is 16. Pretty cool, very useful and then square root. So if you want to take the square root of number youth math, that's sq rt square root on. Then the number you want a square root ban, You've got your square root. Another cool, uh, built in module within python is the random modules. A few knick for some reason to generate random integers, right? The random module has his rand into method, which takes two inputs. It takes the lower and the upper parameters of the the random. And so here I would create a random industry between zero and 10. And if I actually cute, this present shift enter to see the every single time execute it generates a new random integer. If I want to have a little more control over my random integers, let's say I want to just do multiples of five. I have here this Rand rains method Which six? The bottom floor and the ceiling 0 to 100 steps of five For here to give me random numbers that are multiples of five. Every time running, you can see it executes and generates a new brand of number. Um, random floats if you need random floats is used to random method and the multiply at times How many rains? Right? So if I want from 0 to 10 floats right, I would just do random times 10. And you can see here up here, kids pushing it down that every single time I generate that I run this It gives me a brand new random float. The last mother we want to cover here is this regular expressions module, regular expressions of very powerful Montel, and it's used really to read strings or our files that contain strings or messages that continue large strings, that you want a parse out certain parts of the string. So let's say you have this huge text and you want to parse out all the email addresses or a with the numbers phone numbers out of it, etcetera. You would use the regular expressions model. Now we're gonna cover four methods within the regular expressions. Bother. We uncover the find all wrist returns lists. Oh, are all a list of the occurrences of your search term? The search, which returns the first occurrence? Oh, the index of the first occurrence of your search term split, which splits your your input. String in into a list which, which is split by your search term. So let's say you were searching. Um, you were looking at a string off phone numbers and you had a dash in it, and you want to separate the area code from the 1st 3 digits in the last four days, you would do a split with a hyphen as the splitter and sub is the substitute method. Basically, it matches your text and substitutes it. So if you wanted to replace all of the phone numbers in the file, you would use the sub method to use regular expressions. It's best to go into examples because it can get very complicated. You have these meta characters, so matter. Characters are your search your methods of searching eso here. If anything, in square brackets, a set of characters, anything in square brackets with this little carrot fine in front, meaning search for anything that does not have this strength. All right, you got your period, which is a wild card except New Line. You're back slash, which is either escape or special sequences, special sequences of the ones down here, um, dollar times. And with its friend musty. It's infinite number of combinations that you can use. So let's let's go into an example, because it would be much easier. So here I'm gonna create a string, and this string says, please contact us at building. Teach at gmail dot com for more information or visit us at www building, teach dot com or call us at some fixing number 55555555 And let's say I wanted to search for every instance of the word building teach in this string. The way I would do that is I would use to find all method. So I would import Ari right wriggle expressions. And then I would use Ari that find all building teach in my text. And then I would output that. And you can see that there's too instances of building teaching. My texture returns to me. A list with two instances. If I wanted to search for the numbers, anything that's numeric within this string, I would use find all. And then here that the square brackets. Which means a set of characters, right, a Sarah, a set of characters between zero and nine or anything that a number on it would return to you. A list of all the numbers he returned that that phone number in the list. One powerful thing you could do here. Let's say you're searching for, uh, and email address, right? So an email address I would use the find all, and then I would use those special escape characters. In this case, I'm gonna use the backslash s, which is anything that does not contain white space. So if you think about it, if you look at an email address, you've got a word, right? So word does not contain white streaks, white spaces, this the spaces between words. All right, so word does not contain whitespace. Uh, and I'm not looking for only one instance of no waiters and looking for multiple instances . No whites, it's it's It's pretty much the whole word, right? So I would use the backslash as plus, and then I would use the at symbol because I'm looking for the at symbol. Right? So it's a word than the ad symbol and then back slash s plus, Which means another word, right? So in here, if I want to return email address, I would do find all back slash s plus of the at symbol plus backs. I says plus, And that would return to me at any email addresses within about this text. If I wanted to find you RL's within this text, I would I would look for a search term, starting with www and then a word, right? Anything without with with no white space. All right, so obviously building t's dot com. We'll have in the white space, as you can see here returns. All of it turns over right here. Let's say we had another. It's experiment a little, Let's say here my text to equals, um killed and teach and gmail dot com on build and use at the Apple. Uh, what's iCloud dot com? So in here, expect. Let's see what happens if I'm gonna get now to, he must. You can see here from looking for Onley emails. It's going to look for a set of characters with no whitespace, the at Symbol and then Angela dot com. And then the same thing here, since its own in the frame of is going to give me all the instances of of email addresses in that in that string that something very useful. If you're looking for email addresses, So let Z Uh oh, that's so the next thing Search search returns thean Next. Remember a string. Every single character industry contains an index and the index's start with zero, so search basically gives you back the index of the first occurrence of that search term. So building teach right in the original text here starts at index 21 as you can see here, start and ends that index 34 which would be right here. And if I wanted to return the beginning, and then I would use the span. So start method of this search term of this Ah, search result would be 21. The end method of the search is over 34 the span will return to the beginning and the end Very useful if you need to. Now have a counter of sorts within your within your search terms. Split is another very useful method split. Basically. Oh, splits your string, uh, and creates a list out of it based on your search terms. So here I'm looking at a split based on slash lower case. That's remember slash lower case s returns. True. If there are white space characters who here, it's gonna split the the string by all the white space and you can see here it does that it creates a word azan item in the list just pretty useful as well. Uh, sub is the other method we're looking at sub replaces text based on your search term and replaces it with your specified terms. So if I wanted to replace the phone number in that string instead of the 555 number, I were used in 999 number. All I have to use is the sub method, so all of these are very useful. These are all built into the Python library. Give it a try. Try the math module with your with your Constance. Try to convert some floating point numbers. Try to do some absolute values of exponents. Square roots generate some random numbers on Brenda. Mince with step so multiples of five multiple to multiple. 10. Try that out on and generate some floats. Learn a little bit, uh, practice a little bit with the regular expressions that could be very powerful. It takes a little while to learn all the combinations that you can do and give you one brief example. When one very useful one that I mean, that's one that I've used in the past when I'm looking for an email addresses o R u R l Within a huge searched, whether it's in a file or some online references or something like that, you can just use this this Ah regular expression to use that have also. We also looked at the search. Look at the search function for locations of a string, the split splitting a string based on characters and then your substitute on. Remember, as always, there's text instructions at the end of this story, I think. 27. Intro to Python: Getting user input: Hello and welcome back to building. Teach in this attire. We're going to go over getting user input, collecting user input, using the built in input function. Now, the building input function was really easy to use. It takes as and as a parameter the question that you want to display. And then it stores the answer to that question as a string, which is important because if you're gonna do some type of math within your input, you should cast that input as a an end or float, depending on what type of math you want to do. So let's let's let's try it out. So here I have a and I have a variable name. I've said it to my input function. I've set the question. What is your name? You can see it displays. What is your name here? And put my name Henry. Right. And then it's gonna output. Hi, Henry Poma. Right. Hi. Plus, remember, Concatenation String concatenation uses the plus and then the name and it output high. Henry Poma. And that someone here for math. Right? So here I'm collecting input for a first number, and I'm collecting and prefer a second number and I'm adding those numbers. Remember that the the values that you specify with an input get stored a string. So I have to cast them as if I'm gonna add them. And here I am at in them, right. Some equals into someone plus into them, too. And then I'm printing them. So some here is an end because I'm adding to ends. So I have to cast that back to a strength in order to input it. So let's say 10 and then five as the second number, and it will output of some, which is some equals 15 right? 10 plus five equals 15. So very useful. You can use it to test your functions, to test your code with different input values or to, you know, to create calculators or stuff like that. Really useful. Uh, give it a try. As usual. There are text instructions at the end of this video. Thank you. 28. Intro to Python: Decision Making in Python: Hello and welcome back to building teach in this lesson, we're gonna be going over decision making in python decision making in all programming languages. It's a very powerful tool. It allows the programmer to change the output of a program based on some input or based on conditions met by some input. Um, so let's say, uh, if you have ah, log in form with a combination of user name and password, you would have some if statement within your code. That would say, if the combination of user name and password matches the combination of user name and password we have in our database, then allow access else deny access. So that's really what we're gonna talk about in this in this tutorial, if else statements and in Python there's one more concept. Er's if LF and then there's else. So let's go over those keywords if is used on the first condition. So if Condition one then execute this code, then you have this keyword Elliff. Elliff is used on all conditions after the first condition, So if you have multiple conditions that you're testing for, let's say you're testing for some value. If value is equal to zero falls LF values equal to one falls, elliff value is equal to two. True, then execute this code else is the last keyword that you need to know else is only executed if all other conditions are false. So let's go over this in text here. So if is only for the first condition. So if and you put your condition than you put the colon side, you press enter. Then you'll have four spaces, and then you. The code that you want to execute those four spaces isn't is a required indentation. The no pickle Do it for you. But if you're programming in an I D, that doesn't do the indentation or for programming off a text editor, then you'll have to have those four spaces or else the pipe. The python code will fail. The interpreter will fail. The code eso this in Texas for the first condition is if condition one Colin enter four spaces and then the code that you want to execute. If you have more than one condition, let's say in this example here we have three conditions. The second condition would use the L EF keyword, not the if keyword the L F keyword. LF condition, too colon. Four spaces after the enter on, then the code that you want execute. Then again, LF condition three Colin and turn four spaces and then the Cody one execute and then the final condition would be else. Else will only execute if conditions 12 and three are false, and I'll go over some examples in a minute, so it's a little more clear, but the basic syntax is that it is only using the first. Then you have to use the colon. You have to enter than four spaces and then the code you want execute Elliff on the 2nd 3rd 4th 5th all the way toe, however many conditions you wanna put in and then else is only executed if none of the above conditions are true within if statements, you have these things called logical operators. These are the things that you have that you're trying to compare these air, the tests or the conditions. So the first condition that we would test would be equals if my value equals some expected value right and notice that the equal has to equal symbols in it in that one equal symbol one equal symbol eyes used only to set variables or classes. It's to assign it's for assignment to equal symbols are for comparison. So you must remember that eso when you write a condition if a equal, equal B colon space o r. Enter a new line, four spaces and then the condition you won't execute, not equals would use the exclamation point and equal. So if a not equal to be, there's an alternative way to do it. Using the not keyword, which I'll go over in a minute less than uses the less than symbol less than or equal to uses the less than or equal to symbol greater than uses the greater than symbol and greater than or equal to uses the greater than or equal to symbol, not keywords. So if you put a knot key word in front of not a equal equal, be that would make it a not equal to be so. It's an alternative way of saying not equal to. So let's go over some examples in here, and what I do is out. Restart the colonel, clear anything that we have in here sometimes in use and put you have to restart the kernel , which is a way just clearing the cache of that notebook. So I'm gonna have here a test. Right. So I have here, remember, way went over user input in one of the last tutorials. So in here, I have a user input. Enter number between one and 10 and then remember, the value of a user input is stored as a string. So I'm gonna convert that string into an end on and store it in this vow variable. So I'm gonna say if vow, if my input is equal to five, then execute this code print your number is equal to five. So if I were to write a five in here, notice that it's true, it would execute the Prince Damon print. Your number is five. If I were to do this again and I would put a four noticed that the print statement is not executed. All it does is outputs the number you put in there. Um, so that's I mean, it's not a great example of in this state making really nothing. Nothing happens, right? In order to see the value of the if statement, you have to have an alternate. You have to have a else in there. So I'm gonna have the same example here. So I'm collecting number, converting its own end and comparing it to five. And then if it's true, then it'll output this else. Meaning my conditions are not none of my conditions are true. Then it'll output this. So I'm gonna put the five. It will output the first line. If I put a four, it will output. The second line noticed the else is only run when the conditions above it are false. If you want a little more control of your program, then you're gonna put multiple conditions in your program, which which is the example? Laugh here. So following the same example, I'm collecting input between one and 10 creating an end comparing it to five. So if the value I enter is equal to five than it out put your number is equal to five. If the value I enter is greater than five, it'll output. Your number is greater than five. That five. If it's equal to four, remember notice I'm using the l ef after condition one. So anything after condition one where your testing use the l ef Variable. Right. So I'm testing for four people to four equals three equals two. If none of these conditions are true, then the else is executed. So here, let's say if I have four, it's gonna output this code. If I have, uh, one, it's gonna output this cold because one is not in any of these conditions. So therefore, it has to use the else, uh, condition. So practice that it takes a little bit of practice. But once you get the hang of it, you can you can set ah, lot of control within your within your program. So let's go over the conditional. Right? So here, these will all be true because I want them to execute. But I want to show you this in tax. Right. So here I've set this valuable to seven. So I have here a test. If a is not equal to five, then print A is not able to fire. And obviously seven is not equal to fire, so the condition will be met. But this is one of those not equal way did the equal here. This is not equal. All right, let's do the less than equals A. If a A is less than 10 so it will execute A. It's less intended. A is eight lesson 10 so it will execute less than or equal to its the syntax of less than and equal to again. Six is less than seven, so it will execute gray, then use a greater than symbol. Obviously, we'll execute greater than equal to uh, so seven is greater than or equal to seven. It is the not keyword is when we went over earlier. So an alternative way of saying not greater than in this example would be absolutely not less than would be to use the not before the condition. And obviously A is not less than five right bullying conditions. So if you want to test, if you have a boolean variable, right, so here I've set the bully into true, you don't have to do greater than equal to or anything like that. All you have to do is set the bully and in there, so here, I would say, if a then print true. So obviously a is true. So if a print true on, I could I could write another one here, let's say B equals falls. All right, if be if you remember, not be right because not be with me and false Prince B is false. Let's try it out. I see here you can see not be right, cause if means if true if not true meaning it's false then B is false. You can also use end to do more complex conditions. You can use the ends keyword in here. So here I have a equals two and B equals four and have have a test saying If a equals two and V equals four then say both conditions are true elf Both conditions are false and obviously both conditions are true Within here you can use also use the or keyword in conditions. So here I'm testing. If a is equal to two or b is equal to four obviously only one of these conditions True. So using the or it will test either or write it will it will touch suppose Obviously this will come off its true Give these a try Try multiple. You know said some variables test if they're true. Tested to greater than Trish tested equal to use the not keyword experiment of the Nike work. Try conditions where it's just, if an else and then if l if and else practice on as usual, there are text instructions at the end of this video. 29. Intro to Python: For loops in Python: Hello and welcome back to build a teach in this tutorial, we're gonna be going over loops in python now, loops allow you to execute. Ah, black a cold over a set number of times over a set sequence. And there are two types of loops and python. There are four loops and there are wild loops. Now the syntax for four loop would be as follows. Four. Some variable could be acts. Could be I could be It could be whatever you want in range and then the number of times, uh, colon, enter four spaces and then execute some code. Now the notebook will create thes spaces for you. But if using a text editor, make sure you put four spaces after you press enter, put four spaces on, then the code you want to execute a while loop is a little different. The keyword is while Then you set some variable x, a b, a whatever you want, and then some conditional operators remember the decision making tutorial we went over. The conditional operators are equal to not equal to greater than with unequal to less than less than or equal to. Oh, we'll cover that in the last tutorial and then some condition. Whatever condition you're testing for, and then you execute the code. So let's go into an example. It will make things a little bit easier. So let's say for some reason you wanted to print hello five times. Now, one way to do it is to simply write print statements five times and then execute them. What that will do is that will print the string that you specified five times, but that's kind of worried. It takes up a lot of space, and it's kind of the dumb way to do it. The other way to do it would be to use a for loop on here. I have a for loop. Remember the syntax of the four loop? It's for X or some variable. Could be It could be ABC, the whatever you want for X in range. And then the number of times that you want to loop and then colon enter five spaces and print. Hello. So here I'm printing Hello. Five times. So for X in range five print. Hello. Noticed the index. Right. So this this X, what does this? X two X is basically a counter for the range, and the counter starts at zero. So similar to strings. Remember that the very first position in a string starts at zero, and you notice here I'm printing five times with its 01234501234 which makes five times. So that's that's four loop. You can also lope through a string, so this syntax for looping through a string is similar to the in range. The only difference. As you say, you specify your string and you say, for I in your string colon, enter four spaces and the cold you want to execute. So here I'm looping through the words Strawberry, and it's gonna go through eats character in the word Strober, and it's gonna print out the letters or the characters in the loop. Now there is also the concept of breaks, uh, within four loops. So let's say you're doing you're creating some code in which you're looking at a string and you're looking for the character X. So here have created a string, which is a pretty long string, and somewhere toward the beginning I haven't X so I'm looping through the string for I in some string colon. Enter four spaces, print I and then I have a condition here. If I equals X print found and notice what happens here, it'll loop through the entire word. And once it finds the letter or character X, it'll print found. But it's a little bit of a waste, right, because you're still looping through the whole word. And imagine if this was, ah, 1,000,000 character word, you would want it to stop. Assume as it finds the X. And that's where break comes in, right? So what break does it says? Even if the string is not finished or the generator is not finished? If this condition is met, break the loop. So in here, if I execute the same cold, right, so have the code for I in string Print I If I equals accident, break notice what happens here? It only it stops at the fifth character, which is the X. And it does not continue looping, which is a good which is good cold because at this point you're not wasting processing on the rest of the string. The condition has been met, so it breaks, So breaks are a way to break a loop, right? Once a specific condition is met, the other loop within python is a wild loop. Now, while loops are a little bit dangerous, you have to be very careful because if you don't ever meet the condition of the wild loop, you'll create what's called an infinite loop and your program will run indefinitely. So you have to be very careful when you're creating while apps to ensure that the that the test condition is met. So here I have in a while loop that will do the same thing as I specified before it will print hello five times. But I have created a little piece of code here that will ensure that this X, which starts at zero, will hit five at some point. If I remove this and I'm not gonna remove him because you know it's gonna break the program , if I remove it, it will continue printing Hello. Because the condition x less than five will always be true. So you have to make sure that the condition at some point is false. And here work, we're creating the condition as false. The break keyword can also be used in wild loops in a very similar way to the way we had the strength. So here I have the same wild loop that should should iterated five times. But once the X right X equals experts, one hits two. It will stop. So it's another example of of using the break keyword toe break a loop. Try these out. Try the four loops. Try the wild loops. Try Iterating, create a string and iterated through the string. Put some conditions in their on use the break he worked to break once that condition is met give it a try. And, as usual, text instructions will be at the end of this tutorial. Thank you. 30. Into to Python: Lists in Python: Hello and welcome back to building. Teach in this attire. We're gonna go over lists in Python's now lists is a type of collection object. A collection object stores this of data of those groups of data that you want to use in your program. Now there's four different types of collection type, so they all have different features. In Python. We have lists, we have sets, we have couples and we have dictionaries. Now the list is a collection of objects, and it contains the following features. But each one of these has different features, so the lists the features of a list is one that it is ordered, meaning that is indexed, as you can see here. Two. It is changeable, meaning you can change both the size of the list and the items within the list. And three is that it allows duplicate members, meaning, if you wanna have a certain item more than one time in the list of this will allow that. Now, the way to create a list is we use the square brackets, and then we list the items that we want to store in the list within square brackets. So here I have valuable equals square bracket, the items you want, a store and then close square bracket. Now, the way a list stores data is that stores data similar to the way that strings store characters. It stores them with indexes, so the first item on the list will be index zero, the second item index one and the third item index to. So let's let's create a list so we can start playing playing around with lists. So a said before the sin taxes, you have to use square brackets. So here have a shopping list equal square bracket on. Then I have a list of items of milk, bread, apples, eggs and rice. And let's if we print out this list, you'll see that it stores the items in the same order in which you created them. You see 12345 There are five items here in the same specific order. If you wanted to get the length of the list one. See what sizes Lister's. You can see here that this list is five items, right? Remember that the index has started zero. That's what has five items in the last chapter. We went over looping, so the same way you can loop over the characters in the string. You can also loop over items in the string. So using afford a four X in shopping lists next because they hear that it's looping through all of the items in that list. So let's let's take a look at the index's here. So here's another way to loop to loop in index. I'm trying to loop a list, and in this little four loop, it's a little different than the Ford up appear in that it has now two variables inside, and it has this in numerator on it. What this basically does is it has the ability to print out the index and the items so the index would be this numb. And then the item would be this other one. Here, As you can see here, milk is that index zero bread is the index one apples to eggs three and rice for a stated before, very similar to the way that strings store characters. If it wanted to access items within the list, it would be very similar to the way we handled strings. We used a square bracket and then we specify the index were trying to get. So if we violent index, if we wanted the first item in this list, we would look for index zero. So here, shopping list square brackets in the example would give me the first item. If we want the last item in the list, we would do shopping list. We take the print statement up shopping this square brackets negative one negative one would give you the last item on the list. You can also specify four if you know there if you know the size of your list. This is a A list of five items, so five minus one would before we did that it would also give me the last item. But we would have to know the size. We don't know the size. Remember, you can always use negative one, and it will give you the last item lists also support slice notation. Remember, in the the strings tutorial we covered slice notation. Solicitation is very similar, uses the square brackets, but the only difference is it uses two inputs in between a colon. The first input would be the starting position and the last input would be the ending position or the one plus the ending position. So in this particular case, right here, I am looking to start at index to which is apples. And I want to end before index four. So would only return to me. Index two and three, you see here started to and before four. So meaning two and three, as you can see. What? The index. Okay. With the slice notation. Okay. Next, we're gonna cover checking if an item exists in a list using the in keyword. So here we've created the list, the shopping list, milk, bread, apples, eggs and rice. And we want to check if milk is in shopping list. And it's real simple. You just say, if the item looking for milk in your list then execute that code you can see here. Since milk is in that condition is true, it will execute the code below. Sometimes you need to sort of list. So if you want a sort of list, use the sort method real simple, same shopping list on. Then you do shopping lists that sort, and then you print it and you can see that now it's alphabetically sorted. Um, real simple If you want to reverse order list, use the reverse method. Here it is. So I've created something this supplements that reverse. And if I print this out, it's in reverse. Alphabetical order. Reverse off. Better corner. All right, Um, sometimes you want to add an item to a list to add an item toe. A list used the A pen method. The upend method will add the item to the end of the list. So here I've created the same list. I'm a pending one more thing. Cookies. And here, when I printed out here using the pen method when I printed out could see cookies is now added to the list. Sometimes you want to add an item to a specific index in the list, so here are created another list. Here. I've created a list of chicken, steak and fish, and I want to insert detergent at Index one so it will. It will move chicken over, and it'll insert detergent between state and chicken at index one, so the insert allow in certain method allows you to insert an item at a specific index. Sometimes you want to add more than one item. So the way to do that is you upend, uh, one list to another list using the extend method. So here have created my protein list chicken steak and fish. And I want to add that to the shopping list, which I should probably let me copy this one here. I'm gonna put that they're so now, shopping list has milk breads, apples, eggs and rice, and I want to add the protein to it. So shopping list. So the first list dot extends, then the second list. So you can see here that I've added Uh huh steak, chicken and fish to the end of my other lists. One list adding another list of the way to do it is you specify the first list dot extend, and then the parameter would be the second list. Sometimes you need to remove an item from the list to remove and Adam from the list. Use the pup method, and the pop takes a Z a parameter index. So in here I'm removing the first item from the list, which is milk, and you can see here when I return the list that no longer has milk in it. Because I've popped that item out using zero the zero index. Sometimes you want to remove an item from the list using the delete keyword. That's another way to do it. I would. The way you do that here have created a list I used D L D l as in delete shopping this at Index zero. Similar to pop in the difference. It's a It's a different way of doing it instead of pop used the lead, but you still need to specify the index. Uh, sometimes you may not know where the item is, so you want to remove it by value and to remove an item by valley used the remove method. So here have my shopping list, and I want to remove bread from the shopping list. So I would just say shopping list that remove bread and it will remove the bread item from it without me having to know the index to remove all the items from a list and have an empty list used. The clear method you see here as soon as he used clear it returns to me and then delist trial these out tried to remove. Try the clear tried to delete Try the pop to remove. Ah, single item. Add to list together using the extends in certain item at a indexes and the insert a pendant item to the end of the list using the pen method. Reverse sword sore except try a lot of these outs on get some practice. And, as usual, there are text instructions at the end of this video. Thank you. 31. Intro to Python: Sets in Python: Welcome back to building teach In this tutorial, we're gonna be going over sets in Python. So says the second type of collection that will be covering in python will be doing list sets, topples and dictionaries. So sets what are the following? What other features of sets? So one, it is a non ordered. What that means is that, uh, the order that you create the set isn't necessarily the order that the set stores the data in. So you'll see here. I'm creating a set with Monday, Tuesday, Wednesday, Thursday, Friday. But when output to set its output, it's Tuesday, Wednesday, Friday, Thursday, Monday. So I it orders it in the most optimal way it can. But it doesn't order in the in the in the format that you are in the order that you created it to, It doesn't have an index Eso, unlike lists sets cannot be searched by index because they don't have an index. 33 items in the set are unchangeable, but the set itself is changeable, meaning you can add items or remove items from a set. But you can't change specific items in the set. Uh, for four doesn't allow duplicates so sets must have unique values. And five sets are mainly used for, uh, searching. Where was well for scenarios where you have to optimally search for items. So if you want a quick search of a unique list, use a set, so to create a set, it's similar to creating a list. The only difference is you need curly brackets, so variable equals curly brackets. Open current, record your items and then close. Curtis bracket. You can see here I've created a SAT work days on the Tuesday Wednesday Thursday Friday on when it creates, and it creates a ton ordered to get the length of the sad used the Len method. You can see here five items in this set to search for specific items in the set eyes the same as in the list to use the in method. I can see here that I have the in work days. Uh, I'm sorry. The in keyword you can see here have the in keyword in this. If else statement notice that we did decision making, we didn't fl statement, but we didn't cover this in tax of if else statement in this intact, you can actually put in. If else statement in a single line on the way the syntax goals is, you put the if true code than the if condition else if false code, so have very true right. If true, print Mondays in the set. The if condition is if Monday in work days and then the else is else print Monday, not on the set, and you can say you can see that Monday is in this set. So it prints the true condition, which is the condition on the left side of the If statement. The false condition would be the condition on the right side of the if statement, it's just a different way of writing it. It's a more was called Python IQ way of writing it. So if you only have, if else logic and you don't have L if logic or else you don't have multiple if conditions, you can use this one liner format to create an if statement. Okay, let's go back to set, so to look through a set. It's the same thing as a list used affordable forex in work days, it will print out your you're sit to add an item to set used the ad method you can see here . I'm adding Saturday to a new set on when I created. You can see once again. Saturday is in this new set. You can also see that is again a non ordered to remove items from a set. Uh, you have to specify the item you want to remove, since there is no index. So you have to specify here. I'm removing Saturday and you can see here I remove Saturday from the set. You can also remove items from the set using the discard statements, or here have created a another set with Saturday included. And I'm gonna discard Saturday and you can see here it's discarded. Please note that if the item does not exist in either the remover that discard, you will get an error. So we'll go later on. We'll go over, try catch or try, except loops just and you'll be able to handle those there to empty a set. Used the clear method you can see here that if you clear this work days set, you get empty. Set. Another unique feature of sets is you condone Ooh, set operations So set operations are a way of combining two sets. But there are different rules based on which method or operators use. So one set operation is called the Union Operation. So the union operation keeps only the unique values in both sets. So here I have two sets Monday, Tuesday, Wednesday, Thursday and Wednesday, Thursday, Friday. And using the pipe symbol pipe symbol is the union symbol for set operations. You can see here that this list will keep on Lee the unique values between the two lists. You can see that there are two duplicates Wednesday and Thursday between two lists, but it only keeps one of those that keeps the unique values between two such another way to do things. The Union. Another way to do the union uh, set operation is to do this union method in the set. Do you take the first set? That union second set and you can see here it does the same thing. It is exactly another type of set. Operation is was called the Intersect. Operation Intersect. Operation keeps on Lee the values that the two sets have in common. So here have worked is one work days and work days too. And the only ones they have in common would be Wednesday and Thursday. So when I do the set operation and the way that you do, the Intersect operations used the n symbol Andi that will do the intersection you can see here. Since the only share Wednesday and Thursday, your new set on Lee has Wednesday and Thursday. Another way to do the Intersect up set operation is to use the intersection method. So you take the first set and you run the intersection method. Andi pass the second set as a parameter, and you can see here that it does exactly what expected keeps only the common values. The third operation is the difference operations, so the difference Operation removes items from the first set and rate set here for set that are present in the second set, but the way of removing items based on a list based on a set of items that you want to move . So let's say you have Monday, Tuesday, Wednesday, Thursday, and you want to remove Wednesday, Thursday and Friday on. You can see here. Yeah, I have an extra Have an additional one. Let me just add Friday. No error. If it doesn't find it. Obviously way just confirmed that you can see here. This is the remove these items from this list if if they exist. So the way to do the difference operation is you use the minus symbol or you can use the difference methods or set one difference on set to because he here removed thes items from the versus first that if they exist, try these out. Try set operations started moving items, clearing items, adding items, getting the length, creating sets. Player Ramos sets remember their optimized for quick searching of unique lists. Foods is it's the fastest way Teoh to add to your program a quick search of unique list practice these and as always, there are text instructions at the end of this video. Thank you. 32. Intro to Python: Tuples in Python: Hello and welcome back to building teach. And this lesson, we're gonna be going over to polls in Python. So two polls are one of the four collection types available in Python. We've covered lists. We've covered sets. Now we're covering two poles now, two polls are very similar to lists, but there are a few key differences. It's similar to lists in the fact that it is ordered, meaning that when you create a to pull, it is we will be ordered in the same way that we're that you specified during the triple creation. Ah, to pull also has indexes indexes starting at zero, just like the lists. And the Tupelo also allows duplicates just like a list. Where it differs from a list is that a couple is not changeable. Remember that list you can add or remove items within the list, but a couple is not. You cannot edit a Topol. The only thing you can do if you must edit Topol as you have to create a new trouble and also is smaller and faster than a list of performs better and hold less memory than list to create A to pull this in tax is used. Parentheses toe Hold your items here so variable equals perent. Asi open parentheses, your items and close parentheses that's created trouble. It's great A triple again. You need your parentheses and then in between your items so variable equals open parentheses. Your items close parentheses on. You can see here that this list this tipple is ordered in the same way that I specified appear. Since the Topol is indexed, you can also access items the the index. Remember that the index and a full second list starts at zero. So to get the first item off these two bowl, you should use the index of zero to get the last item. If you don't know the size of to pull, you use the negative one, just like on a string, just like on the list. Two polls also support slice notation. So the slice sensation, as I remember from our strings tutorial and our list tutorial slice notation is it takes two parameters in between a colon here, So the first parameter is the starting position, and the last parameter is the ending before position. So it's the last position plus one. So in here have print work Day zero, which means print the 1st 1 print workdays negative one on, which means it's the last one. And here I have print work days from Position one, which is the second position on to position to right because it doesn't include three. So it's the ending position, uh, ending before position three. So it's really 23 on then, here in slice notation. If you omit the first item in a slice, notation on, you just have the last item it it interprets it as starting at zero. So here it's It's starting from 012 ending before 3012 On. If you omit the second part of slice rotation, it just takes it as this is the starting position. So if we started position to it will give you Wednesday, Thursday and Friday. So starting to the end position to get the size of people just like the size of ah list or the size of a set or even the size of string used the Len a method here. So you see, then it's giving you that this Topol has five items to check. If an item exists in the list, same as a stream Samos A list saying I'm sorry to check if an atom existing Topol used in keyword, which is the same in keyword as you would use on a string on the list or on a set. So here I'm checking it Monday in workday that well trained, true or false? True if it's in false if it's not in to nuke through items in the two poll, use a for loop forex in workdays print. Exe. You can see here that it it it a rates through the atoms in the list. Same as a string Samos A list. Same as a set to add items to a to pull. Remember, two poles are not changeable. So to add an item to people, you must create a new triple. So then here have a to pull off work days Monday, Tuesday, Wednesday, Thursday, Friday and then have another triple off weekend days. So in order to t to add these two items to this to Paul, I have to create a new Triple A new took A which is the some or the contamination of the something the concatenation of the 1st 2 topples. Remember, concatenation uses this plus operator on here. I'm just adding the two lists and creating 1/3 22 poles and creating 1/3 to pull from it to remove items from a to pull, remember triples and changeable to remove items. The only way you can do it is to convert to to pull toe a list, using the lists method so the list method will will take you to pull and they will convert it to a list. Then you can use the remove function. Remove method. Sorry off that list to remove that Saturday, and then you can create another two people by using the to pull method and passing as a parameter. The list. So in here I've got a two pool with Monday Tuesday, Wednesday, Thursday, Friday. Saturday, I converted it to a list I used to remove method to remove Saturday, and I created a new triple with Monday Tuesday, Wednesday, Thursday Friday. Try these out, and as usual, there are text instructions at the end of this video. Thank you. 33. Intro to Python: List Comprehensions: hello and welcome back to build a teach in this tutorial where we are going to be learning about list comprehension ins. So what are this comprehensive? So this comprehension are used to create new lists from existing lists or strings or other honorables. They are an elegant and concise way to define and create list based on existing lists or strings or other edibles, and their an alternative to using for loops and lambda functions, which will learn in the future, said Section. Now the syntax of a list combination is as follows. So first is the output expression right, so that's the the expression that you want to act on your list. Then you define the kind of like the four loop within your list comprehension. And then finally, there's a conditional filter, which you could have, which is an optional optional filter, which you can have. Lett's going to an example. It's easier to understand. Let's say you want to add five toe all of the elements in the list. So here I'm creating a empty list. New numbs and an existing list numbs. The numbs has numbers 0 to 10 and I want to add five to each one of these values and populate the new numbs lists. I'm creating new numbers list off of this list, and I'm adding five to each of the elements, so the first way to do it would be a four loop, right? So here have for X in numbs right, new numbers that a pen X plus five and then I'm gonna print than new numbs lists. And as you can see here, each one of the elements in the original list now has plus five. But notice that this required, Ah, a couple of lines of code Here on in Python. It's usually it's it's better to keep your code in one line in a very elegant single line of code on. You can see that you can do that using a list comprehension. So with the exception of the print right, I have here the one line of cold. So here I have. I'm defining the new numbs, so the output off this list comprehension will be empty. The new Nam's not properly the new numbers list. I have my expression right, my output expression and then I have my four loop within so X plus five for four x in numbs . If I print this out all right, you can see that it does exactly the same thing. It takes the numbs original list and it adds five to all of them. And it populates the new numbs list as you can see, a little bit easier to read, a little bit more elegant way to do things on. And it also does perform better, so it is a little bit faster in the four. You can also have a list comprehension with a filter. So in here, what I'm doing is I have again my original list of numbs. I have my list comprehension where I have my new Nam's equals my output expression, my for loop And then I have if x my two equals zero. So what I'm looking for here, x, my 20 If you remember from the math section, this is looking for even numbers, right? So if I run this, it will output on Lee. It will add five toe on Lee. The even numbers within my original list, right? So So the zero is considered even the 22 plus 544 plus 5665 except, as you can see it on Lee filtered. And it only added to to the even numbers in the list and it excluded because it's a filter . It excluded all of the odd numbers of list. You can see that this new numbers list even has less values than the original list. So pretty powerful Onda much more elegant way to to apply functions to a list. Now we're gonna be going over Lambda functions next, so you can see another way of doing it instead of using the the traditional four loop to do things. Eso give that a try. And, as usual, the Texan structures are the end of the video. Thank you. 34. Intro to Python: Working with Dates in Python: Hello and welcome back to Bill and teach in this lesson. We're gonna recovering, Dealing with dates now. Python has a built in module called the date time module, which allows you many, many methods in many ways of dealing with dates, we're gonna be covered a few of them. In this tutorial, we're gonna be covering date time, which allows you to output both the date and the time. Meaning date, meaning month, year time. Meaning our minutes, seconds and even milliseconds. The date module allows you to deal with dates for only month, day year on even day of the week and a day of the week on. Then the time Delta time down toe allows you to take the difference between two dates and P Y. T v library allows you to deal with time zones. So let's start with something simple. Let's create a date current date. So to create a date meaning month, day year, you need the date library inside date, time, module. So here from daytime import dates and I have a variable here today, today equals date right dot today, so that today method gives today's date real simple. If you need to deal with time, and they used the date time module. So from daytime import date time I have a variable here now. Now equals date time dot Now that now method gives you today's date and time, so let's output that you can see it out. Put today's date time. I noticed the format, right. The default format is year, month, day, year, month, day for the date, time of year, month, day, hour, minute, second and then milliseconds for the day. It's just your month day. If you need to set your own date, let's say you don't need today state. You need to set a date for your program. We would do the same thing as states rights, you say from Daytime Import Day. My date equals date to use a date constructor date and then you specify the year, the month in the day out. But this you can see it's year, month day. If you need to manually set the date and time for your program using the date time library of the date time module, you would use the constructor for date times. The date time takes us as a constructor parameter year, month day hour, minutes and seconds. As you can see here it out puts it in that specific format. Every now and then, you're gonna have Teoh. You're gonna have requirements to change the, um, the output format. Now, in order to change the output format, you would output the date as a string on when you output the date as a string, you need thes format codes on these format codes will go into a few examples in a minute, but they allow you to output abbreviated weekdays, four week days, days of the week, um, and then the date number with zero padding the month with full name etcetera. So you can see all of these. That gives you a lot of flexibility to output a date as a strength. Remember it output as a formatted string. So let's go into an example here. So in here, I need to output my dates in this format here. So instead of the year dash month dash day, I wanted in year forced last month, forced last day and then the hours not in 24 hour time, but in 12 hour time and then I want to PM also so I would use a code for that. Right? So I have created my date time object here, just like we did in one of the prior examples. But now I'm gonna create a formatted string toe output that date as a formatted string. So the way we do that is we use the string from time str f time method of the date time object and notice you take as in as a parameter, the format you want to output in. So this is a formatted string that you want output notice. I used the percentage lower case M, which means I need a zero patted month. I use the percentage lower lower case D to do a 000 padded day. A percentage capital. Why? To give me a full year with century number. I used a percentage capital I to give me a 12 hour zero Pettitte number and a percentage Capital M to give me a zero patted Ah, a minute on. Then I used the percentage p to give me the A M p m and notice output the type of current date time. Because it is not a daytime object. It is actually a formatted string. You have to get that clear, right? You're when you for when you use format cold, you're not out putting a date. You're out putting string, especially when you use this string from time on DSI. How you can see here, how the output came out now, every now and then, you have to do the reverse. You have to go from a format. It's string toe a date because you have to do something some day calculation within your program. So the way you do that here, I've started with the reverse have taken this string, and I want to convert it back to a date. Now to convert it back to a day, you have to tell python the format that you used or the format that is used in that string so that it can parse out that form and create a date time object you can see here I've created I brought in from daytime import daytime, have a string here that's formatted in in this month for slash day for us. Last year. Space 12 hour time. Colon 30 and then p. M. Am. Alright, so I've told it here to use the format that this date string is in, and then it will convert that string into a date. Time optic notice Here, output, the type of current date and the type of current date is no longer a strength. Current date is now a date time object in which you can now use it for date. Time functions. Okay, so if you wanted to take the that way here, it's to get the difference between two dates. So to take the difference between two dates, we use the minus operator. So here have created two dates. So from daytime import date, time and dates I don't really need date time in here any time. No, I don't need data. So from daytime import date, because we're only using you notice we're only using dates here. Right? So today's date I said as 28 2019. And then the future date will be 11 9 2019 So the difference between the future date and today is 274 days. So a nice, easy way to calculate the difference between the two days. If you want to add days toe a date, you would need the time Delta uh, library. So you can see is t one equals time. Delta equals 100 days. I want to add 100 days to today's date in order to do that any of the time. Delta object to do that. So here have $10 of 100 days today's day and then the future date is today. Plus my time Delta plus 100 days, and that will give me the future days. 35. Intro to Python: Creating Functions in Python: Hello and welcome back to building teach in this lesson, we're gonna be learning about functions now. Function is a reusable block of code, which only runs when it's called. There's a lot of power and functions you can create a function ones using multiple times in your program. Uh, you can, uh, share it ast part of library. It's one of the main ways that you will be programming in Python. That and the using of classes, so creating functions and using of classes of the two main ways that you'll be writing your programs in Python ended pandas when we get to the Pandas Library. So in this is the Tory we're gonna cover how to write and call a simple function in Python . How to write a function that takes a parameter. I had a writer function and takes a parameter and uses default values and had a return of valley from a function. So let's go over the 1st 1 calling a simple function. So it's a writer function in python. You have to start with the death keywords right, and then the function name and then parentheses and then the colon. And then when you press enter, you'll have to do the four spaces usually the I. D e or the nopal. Go handle that for you. But if you're using a text editor, use four spaces and then your code. Right? So here have a very simple function that have a world function that outputs Hello world. So if I press shift into here now defined my function and in order to call this function or I have to do is write out Hello World with parentheses on it and you can see that outputs dysfunction. If I wanted to call it multiple times, I just have to write it again. Or, uh, I could write a for loop for X in range range five. Colon tab. You can see here that it writes my function. Oh, are outputs my function five times, uh, so that writing a simple function and then calling the function so you can call it either by itself. Hello, world. Or you can create a loop. Call it within a loop. You can see here it's output six times. Um, pretty simple. Now, sometimes you need Teoh Add a parameter to your function because that parameter is used within the logic of your function. So to write a function with a parameter, you simply put the parameter within the parentheses. This tells Python to expect a value, you know, and then you can use that value within the program. So here, have a hello function. And then I have a name as a parameter, and I output Hello. Plus the name my precious dancer here. I'm calling that function and notice. I'm putting the parameter within the parentheses of the call for the function you can see here it outputs. Hello. And then whatever you put in there, I could just say, Oh, John, let's say you call this a few times. John, Mary and then Paul on this will output notice. Here is the magic of functions. I don't have to rewrite the code. I just have to call the function time. Now there's a simple function. There are functions with many lines of code, which you would have to repeat that code, which is kind of a dumb waiter. Program functions give you the reusability in code. So notice here. I just have to call it multiple times and passed different parameters to it. Now, what if you have a ah function where? Let's say you have multiple parameters or you have, ah, function that Oh, most of the time Will will expect this parameter, but it also has the flexibility to expect other parameters. Right, So a default prouder. So a default parameter, you will put ah, name or a label to your parameter and then eight default value. So in here I have a hello. And the default value for the name right is Bob. So when I call this function without specifying my parameter without specifying anything, it will use the default values here. Noticed it will output. Hello, Bob. Which is the default value of this parameter? If I wanted to specify my own value, all I have to do is set the value. And here I'm calling hello again. But this time I've specified John notice that didn't use the default family used a value that I set for that name parameters. Pretty simple. Now, most of the time, you're gonna have to output and Dallas, you're gonna you're gonna have some data, you're gonna process that data and then you're gonna output and return that data in order to return data from a function you need the return key word notice. Here have the return key word. It's green because it's a keyword on it will output the value of dysfunction. So here haven't add function where it takes two prominent notice. If you need more than one parameter, you just separated by comma, so this could have multiple parameters on you can have parameters with default values. Also in here, I'm gonna add 5 10 right, which returns notice it returns the value of 15. So that's it's pretty simple to write functions in python. Remember that functions are reusable blocks of code that are only run when that function is called. Try these out, right, your own functions, right Functions that take parameters, raid functions that take parameters and default values functions that return value Practice makes perfect, and, as always, there are texts. Instructions. At the end of this video. Thank you 36. Intro to Python: Creating Classes in Python: Hello and welcome back to building teach. In this tutorial, we're gonna be going over creating classes and using classes and python. Now, python is an object oriented language. What does that mean? I'm here. Object oriented languages allow you to structure your programs in a way that both properties and behaviors are bundled into objects. You've been using classes in every single tutorial in this series because everything in python is an object and is defined in the class. So the strings lists, floats, dictionaries, SATs and everything else that we've been using up to now has been an object. And you can tell it's an object because we're able to access both Thea objects attributes and also used the methods within the object you saw within the list method had the Penn and we had to replace methods, everything that we've used up to now has been a class. But in this story, we're gonna learn how to create and use classes. So in this lesson, we're gonna create a to do list class. We'll learn creating a basic class creating both public and private variables in station essentially ating objects from a class accessing private and public variables, creating class properties in assigning values to them and creating class methods and calling them so let's get started. So let's create a basic class. We're gonna create it to do list class. So it's great a class you need the class keyword in the name of the class and then parentheses and semicolons similar to if a function which we learned in the last tutorial. But in this one in studies in the death used the class class to do list parentheses, semi colon, not seven. Now classes have attributes, right? So in order to define class attributes, you need this built in function. This in it function here. So you use the deaf, which is the function key word. Then you you need to use the underscore underscore innate underscore, underscore and then parentheses. Self, you always need self and then the variables are properties which you wanted to find. So, in my to do list, I'm gonna define a name for my to do so we can have like, this is my shopping list. This is my work list. This is my home list. Acceptable reusability trying to reuse this class in many different ways. So one of the things I want to add to my to do list is a name, so I can identify which to do list. Am I using? So I have here self dot name equals name. In other words, when you in Stan, she ate this class, you're gonna give it a name and it's gonna take that name and it's going to store it in its properties Self dot name. So you have. And this is what's called a public property because you can you can modify it when you Instead, she ate the class. The to do list will also have a list in it and notice that this is a little different than the name. This one has an underscore underscore before the name of the property underscore Underscore allows you Thea Bility to create it was called a private property and here I've created a private list. The reason I created as private is because I want that list to Onley be set and got within that class. If you had made it a public property, then you could create a list outside the class and just give it to your class. But I wanted to I want the list to be stored within this class and to be a property of this class alone and to be access and modified via the class. So I've created was called a private variable here. Now, when you use a private variable, you can't just grab the variable, which I'll show you down here, you have to create a method to get the variable. So I've created a method here. Death, uh, get to do items you have to pass self always in any method within a class, you have to pass the self before you pass any of the other attributes o r. Properties on here. I'm returning self dot items. Okay, so now I've created in my class to use this class and to create an object out of this class , you would have a name of variable equals, and then you have the constructor. Constructor, is this class right here this ah method right here. So I'm saying to do list. So that's my class name, parentheses. And then I'm able to set the name, name my to do list. So since it's a public variable, I'm able to get the name simply by saying my list that name and noticed that it returns my to do list as defined in the constructor. But notice here, I can't do the same thing for the private items. If I If I execute this cell, I noticed that it gives me an error. Why does give me an error? Because it's a private property of that class because of the underscore. Underscore. So the only way to get that items list is to execute the method, get to do items notice here. If I execute this, it returns to me and empty list. Because when I create that class it in Stan, she ate, Sit with an empty list. Remember, a list is instance is created with the square brackets open close square brackets. So notice here that when I go on access, get to do items. The method I get back that list now, this is okay, but we need to add some methods to this class to make it useful. So here I'm defining two more methods in this class. I've defined it. I defined one method to get to do. I am in the class definition above, but here I'm defining another method at to do items, right? So remember, when you add in methods to a class, you have to start with the self and then the attributes that you want to add to that method on here I have a task. So here have self that underscore underscore items that upend. Remember upend when you need to add an item to a list used the a pen method and I'm passing the task that I defined. So what this method does is it add an item to my items list And then I also add another method remove to do items which I passed the self and the item which I want to remove and here on passing self that underscore underscore items that remove and then the task which I don't wanna remove. Remember, the remove method of a list gives you the ability to remove an item by its value. Eso Here, let's ITT's people to try. So here I'm gonna in stand shape. I'm gonna create my object. My list goes to do list. Call it my shopping list, similar to what we did above here. I'm gonna say my list that add to do items here, I'm gonna add Get milk to my to do list. Get steak to my to do list and they get candy to my to do list. If I run, get to do items. No, I didn't understand. She ate that. If I always remember toe to press shift, enter on your class definition or else the python. No people not recorded. So here, here, As you can see, I have a to do list, which is called my shopping list, and I've added three items to the list. Let's say I'm gonna diet. I don't want to eat candy. So I say, You know what? Let's remove the get candy So all I have to do to remove to get candy is my list that removed to do item, which I find up here and I value get candy and it will remove that item. And then I will use the get to do items to return the animal noticed now that my to do list Onley has to items in it. So that's those are the basics of creating a class. Remember, In order to create a class, you need the class definition in order to create properties for a class you need the innit method, and the minute method will take as a first, uh, variable the self and then the property that you want to define. If you want a public property, public properties are set with the self. That name equals the the variable that you're passing. Private properties are created with the underscore underscore and then the name, which you want to use on. Then, in order to get private, you need to create a method and get method to get it. And in order to modify private, you need to create methods to modify as well. Give that a try. Try adding different methods to your to do list on. I'll see in the next tutorial. Remember, as always, there are text instructions at the end of the video. Thank you. 37. Intro to Python: Creating and Using Exceptions in Python: hello and welcome back to building teach. In this tutorial, we'll be covering exception handling in Python now. What is an exception on exception is an event that occurs during the execution of your program that will destruct the normal flow off the program instructions. In other words, there is an error event during the program that disrupts its normal instructions. Now what Python does is it creates this exception object, and it raises it and returns it as output of your program. Now, this exception object contains information on the error that occurred during the execution of your program. No exception. Handling is good practice when writing any program because it helps you handle unwanted behavior. Now Python brings a lot of built in. Exceptions will be looking at Three of them were looking at Syntex error. I would be looking at type er we're looking at zero division ever on. We'll look at a link that contains all of the other built in exceptions. We'll also learn in this tutorial how to raise our own exceptions with with maybe more detailed text in the cryptic built in. Exceptions will also learn how to use assertions toe handle, unwanted behavior. An assertion returns an assertion exception, but they're easier right there, Usually just one line. It's a more elegant way of handling. Errors will also learn how to write, how to handle exceptions, using the try except and final blocks, which will give you a little more control over how the program returns. An exception. And it gives you a little more of a a natural flow to your program. So let's take a look. I have a link here for the Python documents, which has all of the built in exceptions that are already built into Python, you can see is a bunch here. Memory errors, name errors, type errors, etcetera will cover a few. Right now. Let's let's go into that. So in here I have a very simple program that has an if statement, but it has it an error in our syntax. Syntax errors are errors where Python expects, like a semi colon or expects closed brackets or something like that, where you just made a mistake in the writing of the syntax of the program. So here, if I execute this code, you can see that python is pretty helpful. It's pointing toe where the syntax error occurred. So if you know if statements, you know that it expects a colon here. So if I If I If I fixed that and I put the colon and noticed that the error this syntax error does have it for remove it, you'll see syntax errors. So it's a way of helping you to debug your own programs. And then they're very helpful, actually, points to the line, uh, where the error occurred. You can see here. It's telling you that the error occurred here on line three, so you can see that this is this exception. Object returns, information on the error that you have in your program and even the location of the error in here. I have another program. Have ah, hello, World Program on. If I and you can see here that I'm printing something when you print something, Python expects a string, but here I'm putting a Boolean in there and notice what happens. It tells me, have a type error, because I it's expecting a string, but I've put in a Boolean. It also gave me another error here, called the name error, because I've been named attributes a here named parameter right here. And it's expecting you to put a some value in here that is of type string. Since I put of type Boolean, it actually returns to errors, and it tells me where the issue is. And this would help me to, uh, debug and fix my program, right? So I could just say Henry here, and all of a sudden the program works, right? So it's it's a way of helping the programmer, uh, fix their own maybe type polls or errors in their code. Another one we have here is division by zero. Division by zero usually occurs when you have some input value that you didn't. Maybe you didn't mean it to be zero, but it returned. Zero on the risen by zero can be done in math, so it will return to that was invisible error. Okay, so we cover the built in exceptions in python. Um, but what if you want to raise your own exception? What if the built in exceptions do not cover the exception that you are seeing in your program now, in this section, I created a class called bank account right here, and the bank account has a private variable balance, which starts off zero. It gives have a method here to get the balance that returns your current balance. Have a method here to deposit money, which allows you to add an amount to your balance and another method here to withdraw your money, which subtracts in amount from your about. So let's it's processed. Shift, enter and let's execute. Let's Instead, she ate the bank account here and get our current balance. You could see that the current balance is zero, because the starting balance is zero. Now, let's say, if I when I had in and executed the withdraw money method of $100 then I went and got the balance notice here that the program didn't stop you from the drawing. $100. Even though your balance is zero now, this is obviously unwanted behavior. You could withdraw $1,000,000 here, and you would. Your bank would go broke, right? So let's raise an exception if the funds requested are greater than the funds available now . To do this, you would rewrite the would draw method with a test here. If amount is greater than the current violence, then raise an exception, right? In a general exception that would return a message funds requested are greater than funds available if the funds are not greater. If the amount is not greater than the balance and it would go ahead and allow you to withdraw the balance his press shift, enter here, too, to save this version of bank account. And let's try that same sequence again and notice here it raises an exception, and it gives you the instructions here that the funds requested are greater than the funds available. In other words, it didn't allow you to winter all your funds. Instead, it gave you a detailed, uh, messages right off where the exception occurred. So you raise the exception here, and it's telling you this is where you raise the exception because it failed to pass this if statement and it gives you an exception here. Now, this is This is fine, for if you're a programmer and you just you want toe, see that that he ever would occur, right? And this is one way of raising exceptions. Another way of doing the same thing we just did here is to use an assertion now, an assertion is one line of code and it's and it's much easier to read. As you can see here, I have the same withdraw method. The only difference is I don't have the if statement here. Instead, I have one line that said, as that says assert, Right and the Assert statement has a condition that is always supposed to be true, and it's false than it should return a message that it has after the comma. So here we expect that the amount should always be less than the current balance. So I'm using assert, and then parentheses amount less than self doubt balance. And then I have a common here for the false condition, right? So if false, then it will tell you withdraw the night because you're you're amount is greater than the current balance. So it's it's precious. Enter on this cell to save this version of the class, and let's try the same quota to try before, and you can see here that it raises an assertion error over up here. It raid it, raise just an exception. But in here it raised in a different type of object called an assertion error, which again tells you detailed instructions off where the error occurred, Right? You can see here it occurred online. Nine, and it gives you the error message, so it's a different way of raising an exception. The difference here is this is an assertion a little easier to write, a little easier to read on. You could have multiple search statements in your coat. So if you have code that expects a non zero value, he would assert value greater than zero else the ever. If you have, ah, code that it expects a string, you would say if values of type string house this error. So it's a way of handling your possible scenarios where you have some unwanted behavior. Researchers are heavily used in testing Also. Now, this is all fine and good When you're writing your program, but no user, you don't want your users to see this type of message. This is more for your logs. This is more for your developers to see. You may want to write this to a log instead of out putting it to your user. Um, another thing you can do is you can do was called exception handling, where a just a message would be returned instead of the big error. Right? So an exception handling you have this try except and finally block. Now, here I am. I'm rewriting again. Would draw money function method here. Right on in here. I have the same asserts statement on Then I have my return message. The only difference is I have this try. So this try will try the code and it will execute your assertion. Erica's it's safe. If you put an amount greater than the balance, it will give an exception. But in here you will catch the exception and you will return just a regular text message without all this noise and details here, which is really more for your logs. Oh, are you know, for your back and team to look at All right. This is This is more than the text message that you would probably want to show in a u y. Right. And then eso this catches it and returns a more elegant message, right? And more text message. And then we have the finally finally always executes. No matter if the code is has an exception or if the code doesn't have an exception. So that's that's its precious center to store this version of the class. Let's try the code again and you can see here I instead she eight in my account, I deposited $500 I would drew $600 which should give you the assert error. But instead of this big, ugly all these lines of code and more log type of message, you get just a simple string withdraw denied because 600 was greater in your current balance if I were to execute this code again. But this time I'm gonna take out $400 for a time. And instead she ate my class. I'm gonna deposit 500 withdraw 500. Notice that it will give you the success message. $400 were withdrawn from your account, your account balance in the $100 and notice that the finally all also executes. It executes in the in the code where you have an exception. But it also executes in the code where you have a success scenario. Try these out. Try working with the built. In exceptions, try raising your own exceptions on. Also, try the assertions and the try, except finally block on as usual, will be text instructions at the end of this video. Thank you 38. Intro to Python: Lambda Functions: Hello and welcome back to building. Teach in this tutorial will be going over Lambda Functions Atlanta functions, also known as anonymous functions and pipelines. Typical functions and python are are created using the death key word as you saw in the functions tutorial anonymous functions Don't use a deaf keyword. They used the Lambda keyword. Their basic syntax would be lambda the arguments of your function and then the expression that you want to act on your variable. So let's say here have a a variable cold add five and I'm the finding a land function of X and then X was five. So whatever, whatever you pass to the Lambda five will be added to it. Right. So ex experts five. So here I'm adding 5 to 10. So way expect to have 15. Right. So X is the input. X plus five is the expression that we're applying to that input And were you? As you can see, we're using the variable here, so add five equals 15. If you remember in the last tutorial, we also covered list comprehension and Lambda functions are also an alternative to list comprehension is, or even to four loops you can see here that we have the exact same exercise that we implemented in the last tutorial about list comprehension. And this is adding five toe all the values of an existing list. So I have the original list here, starting at one between one and 10 and then I have a new values variable because list and then we're using the map function in here toe. Apply Theo Experts. Five. Land Anonymous function to the My values list. As you can see here, it does exactly that, right? So I'm passing the land of function right. I'm passing the X Plus five to all of the values into my values list, and then I'm creating a list from it. So basically, the map function eyes used to apply the Lambda function to every item on the list. It's a map well, basically iterated through the list, and it will apply the Lambda Function to the my values list, and it will yield a new list called New Values. So again, this was a little bit more complicated than this. Comprehensive. This company is a little bit easier. Four loops is the easiest one. The reason I'm covering Lambda Functions here is because we use lambda functions heavily in our pandas, which will be the next section of this tutorial. And you should be familiar with the way the syntax works. So give it a try. Ondas Usual. There are texts instructions at the end of this video, I think.