Thank you. Hello there. Welcome to data analysis with Python zero to pandas. This is a free live online certification course, or brought to you in collaboration by Jovian.ml and FreeCodeCamp. This is a five week course, and we're starting today on the 15th of August, 2020. Uh, and, uh, we have live lectures every week for two hours.
So we're doing this course live in English and Hindi. So if you want to join the English lecture, which you are watching right now, you can watch this from 9 PM to 11 PM Indian standard time on Saturdays for the next. Five weeks.
And the, the Hindi lecture is from 11 AM to 1 AM IST. On Saturdays for the next five weeks to get a certification for this course, you need to register at zero to pandas.com, but you can watch all the exercises and all the materials for free on YouTube and on, on the platforms that we share you share the materials with. So I'm your instructor. My name is Akash.
So I just want to tell you a little bit about myself and why maybe you should learn Python from me. So I'm the co-founder and CEO of Jovian.ML. And before this I've worked as a software engineer at Twitter.
where I've worked in data engineering and software development views, Python extensively there. I hold a degree in computer science from IIT Bombay, a college in India. And in the past, I've also been a world finalist at the ACM ICPC, which is also called the Olympics of programming.
It's an international contest. And I have been using Python for the last 12 years. So what we've tried to do here is we've tried to put together some of the learnings that we have in Python and in data analysis and share them with you. You can find me on Twitter on at Akash. Jovian or ML is a sharing and collaboration platform for data science.
It allows you to take your data science projects and share them with the world. We will be using Jovian extensively during this course to share all the materials with you, so you will get to learn more about it and free code camp.org. If you're not already familiar is a great place to learn to code for free. You can build great projects and interact with a worldwide community and probably even get a job with a lot of free certifications that they offer. So do check out free code camp.org.
Now, quick overview of the course before we get into it. So as he said, this zero to pandas is a coding first introduction to data analysis using Python. So we will be, we will be talking about data analysis, but we will not go into.
a lot of theory rather we will write code and through code, we will learn whatever mathematical concepts we need for data analysis. Uh, these are video lectures with live coding on cloud-based Jupiter notebooks. So I will be coding live and I will be showing you some code. You do not need to code live along with the lecture. We do not recommend that.
Uh, you can actually try out all the material will be available to you. So you can try it out afterwards. And there are also assignments. So you will have the lecture material, but you will also get some assignments where you can practice these concepts. And if you complete all the assignments and exercises, then you will earn a certificate of accomplishment.
So this is what the. I think it looks like, so there's a certificate offered by Jovian.ml and this will be signed by, this will be signed by me and this will be signed by Bocans from freecodecap.org. Now let's take a look at the course curriculum.
So today is the first lecture. And today we are going to talk about introduction to programming with Python and the Python programming language is a great language is really easy to get started with. So obviously we cannot cover everything. It's a huge language.
I still love. learn something new almost every week, but we will cover the parts that are necessary to start doing some data analysis. And in fact, you'll do that in the assignments that you do after this lecture. Then we will move on to the NumPy library. NumPy is used for numerical computation in Python.
We will see how to perform statistics, things like getting the mean, median mode, and things like that with NumPy. Next, we will analyze tabular data using pandas. So this is zero to pandas is the title of the course pandas is a library, just like numpy and Python has these great ecosystem of data science libraries that we are covering here.
So pandas allows you to work with tabular data. You can think of it like a working with spreadsheets, but instead of using the user interface, you will be able to use, write some code, just a few lines of code, and it is far, far more powerful than spreadsheets. So if you know Excel, then by lecture three, you will be able to do a lot more. Then the fourth lecture is dedicated to data visualization with matplotlib and Seaborn. These are two great libraries for visualization.
You can draw different types of graphs, line graphs, bar graphs, heat maps. I don't want to say pie charts because everyone, well, pie charts are too overused, but there are a huge variety of graphs that you can create with these libraries. So we will learn these libraries, but we will also learn data visualization, how to use it, when to use it, which type of graph to use.
And finally, in the fifth lecture, we will bring all this together to do exploratory data analysis and do a case study of a real world. dataset. So it will be a large real world dataset. And we will first learn to ask the right questions about the data, come up with some interesting questions. We will also learn to identify the right tools for the job.
When you have a question, what is the process of breaking down that question into steps? And then we will also learn how do you actually So there's a lot of material we will cover and we will cover it gradually. So don't worry, even if you're at a beginner level, if you just know a little bit of programming, maybe you've taken a small Python tutorial, maybe not, you should still be able to catch up.
And there will be a weekly assignments. So there will be three weekly programming assignments that we will give you a, here, you will get to practice your skills and learn by doing. You will also be able to give and get help from the community. So the community. is a huge part of this course.
And I'll talk about that a little more. So you have to do these three weekly assignments, and then there is a course project at the end. And this is something that brings everything together for you, where you will get to work on an end to end project involving the real world dataset that is picked by you, and you will get a chance to apply all the tools and all the techniques that you've learned in this course. And the goal of this course project and this entire course really is to create something that you can proudly showcase as your own original work on your professional profile.
Right. A lot of times it so happens that, you know, some standard courses. times have standard projects, and then everybody ends up doing those same projects.
And then that decreases the value of those projects. So here we want to try and create something unique that you can do. And we'll share a lot of ways in which you can do that.
So to get the certificate, you have to submit all the weekly assignments. You have to complete the course project and you have to follow the academic honesty policy, which essentially is no plagiarism that is, uh, do not take somebody else's work and claim credit for it. Right.
Uh, if it is, it is okay to discuss it is okay to ask, uh, it is okay to collaborate with people, but, uh, always give credit to your sources. That's all it is. Now, before we get into the material, just, I just want to share based on our experience of running these courses before how, how you can maximize your learning.
So something that we have found with the participants who've done the best, who've gotten the best results out of these courses is to do four things. And each of these is equally important. So the first one is to watch the weekly lecture videos, which is what you're doing right now.
So every Saturday we have these lectures. If you can join live, please do that because that forces you to adjust your schedule a little bit, but make sure that you can watch this lecture on time. If not, please try to watch it within the weekend. So on Saturday or on Sunday, and then. Then, as he said, the next step would be to write an experiment with the code, the code that we will share with you.
Do not do that during the lecture on the lecture. You just sit back, relax, and just pay attention to what's what we're doing. Then the, then a very critical step, and this is what will actually help you really learn and understand is to discuss, help and interact with other people on the community. So there will be a lot of people asking questions, try and answer questions on the community forum.
And we'll show you how to use it and try to ask questions as well. Try to ask maybe one or two questions every week, try to answer four or five questions every week, and if nothing else, just read through it and like the post that you see, so maybe try and like four or five posts every week. This will keep you motivated, especially as we are all learning from around the world. Um, and then the last thing is the exercises. You know, if you do the exercises over time, over the course of five weeks, a lot of these concepts will sink in slowly and you will apply them many, many times and you will become, uh, you will develop some sort of an expertise.
So that's it. Uh, let's get started then. So the first thing that you need to do is to go to the course page.
Now the course page is zero to pandas.com that is a Z E R O T O P A N D A S. And when you open it up, the, it takes, it brings you to this course page. This course page contains all the information about the course. So this is a page where you have enrolled for the course. If you have not already enrolled, you should see an enroll button here.
So please enroll if you want to get emails about upcoming lectures, if you want to get access to the forum, if you want to submit the assignments, but you can also just watch the lectures if you want to. Now, if you're already enrolled, we are still accepting registrations. So please share this with your friends so you can share it on all.
You can share it publicly or privately. And you can go through the details here. There are also some links here. There's a link to the course community discussion forum.
There's a link to a frequently asked questions, and there's also a schedule you can add to your Google calendar. Oh, and then we have the lessons and the assignments. So here are our lessons. So we have lesson one, then assignment one and listen to assignment two and so on. And we will be using this interface to share all the material with you and for you to be able to submit assignments to us.
So let's open up lecture one. So here you will be able to see the video. You know, anytime you need to come back, just go to the course page, open up the video. And, uh, from this point on, you know, you can see what are the, what's the material, the code used with this lecture. You can just scroll down and see it, or you can see each piece of code, each a mini tutorial on its own page by clicking on these links.
So I'm just going to open up the first link. Oh, all right. So now what you're looking at is a tutorial, a Jupiter notebook, and we'll, we'll cover what that means.
A Jupiter notebook hosted on jovian.ml. So Jovian.ml is a platform where you can share these Jupiter notebooks. So what.
you're looking at is the first tutorial that we will be doing today. The first part and what we need to do this contains some code. This contains some explanations. Now we need to be able to run the code.
Okay. So I am going to run the code, but I would request you not to, because we have thousands of people on the live stream and we are using some free online resources to run this code. So not all of you will be able to run the code. Some of these things might slow down.
So that's why I just watched the lecture. And if you want to ask questions, I'll tell you how you can ask questions. Uh, but do not run the code right now. Do it after the lecture. Okay.
So while that starts, so when we click run, we take the same code, we take the same code and explanations and everything, and then open it up on an online platform, which allows us to execute this code. But while that starts on the lesson page, you will find a link to a discussion forum. So you can just click this link.
And that will open up the discussion forum. And this is the place where the community has discussions where you can ask questions. So on the lecture one introduction to programming with Python discussion forum, you will be able to sign in with this.
Same ID with the same login that you've used to enroll for the course. Uh, this is the same login that will be used with Jovian or ML as well. So here you will be able to log in.
And if you have a question, just scroll down and there is a button here at the bottom called reply. It's a, I don't know if you can see it, but it's a big blue button. Oops. Yep.
So yeah, there's a big blue button here. It's called reply. So you just click the reply button and then you start typing out your question.
So for instance, if I'm, I'm typing out. And that can, that will post your question. Now, if you just want to afford, if you see a question that you like that you also have, maybe just click the like icon.
And what we will do is during the, during the lecture, we will pick up three to four questions, three to four times and answer them just the most popular ones. All right. So that's how you ask questions. So moving along, I click the run button and that opened up an interface like this. So what you're looking at right now, what are you looking at right now is called the Jupiter interface, right?
So Jupiter is a well, if you've used any integrated development environment, so a place where you can write some code, a place where you can execute some code. That is what Jupiter is. Jupiter is an ID. or integrated development environment, and it is hosted. It runs completely on your browser. That's a great thing about it because now what's happening is that, uh, well, if I zoom out here for a bit, is that I'm looking at this Jupiter notebook running on my browser, but it is actually the actual execution of all the code will happen on this somewhere on this server called hub.mybinder.org.
And. No, they have set up a lot of free servers for us to use. Very kindly.
So the actual execution will happen there. Okay. So right now, what I'm looking at is the files.
So the files associated with my project. And the file that you want to open up is called first steps with Python. So just click the first steps with Python file, and that will open up this file for you to see. So now, now we're looking at this file. You know, this is the same file that we were looking at earlier on Jovian.ml.
The same thing that we are now looking at within the Jupiter notebook. Now a good analogy here is you can think of Jupiter itself, the platform as Microsoft word, you know, something like Microsoft word or Google docs, where it's a, it's a platform where it's a software for building for writing these files. And then these files themselves, you can think of them like a word document or a Google doc document, right?
So this is one document. It is called four steps with Python. The IPY NB extension represents I Python notebook.
So I Python is where Jupiter originally. the project Jupiter came out from. Okay. All right.
So the first thing that I'm going to do is I am going to click on the kernel menu and click restart and clear output. What this will do is I've written some code and I've executed it. And there are a lot of outputs of the code.
I just want to remove them so that we can execute the code from scratch. And then I will also just hide the header slightly so that we have a little more space to see things. Okay. So now we're ready to go. So this is our first step with Python and Jupiter.
Um, we will, we will, this will be like a quick Python tutorial. We will not be able to deep dive into everything, but we will pick up all the important topics that we need to start doing data analysis and when, while I go through this material, I will leave out some of the things as exercises for you to try out. So that, you know, so that we can actually get through everything today within time.
But there's a lot of detail. There's a lot of explanation here. There's an explanation on how to run the code.
So we have, we are running it online. So we use the run button, but you can also run it on. your computer locally, and there are some instructions here. The setup is a little bit advanced, so I would recommend skipping it. If you are just getting started now coming to Jupiter notebooks themselves, no, this document that we are looking at.
Well, this document is a very interesting document. It is made up of cells. So you just, it is like a stream of cells.
So you have sell after sell after sell and sales can contain explanations. So here I have written some explanation in a cell or cell can contain some. Code or some programs written in Python.
Now cells can be executed and their outputs can be viewed right within the notebook. So which that makes it a really powerful platform for experimentation, right? You just type something and you run that code and see its output.
Then you change it and try it again. And then you add some explanation using a code using a text cell. So it's, it's great.
And we really love Jupyter notebooks. That's why we've built so many things around it. Okay.
So the first thing that we will do to get started with Python is to start using Python as a calculator. That's the simplest way to use it. And what you can do is you can simply write and execute Python code by adding a code cell within.
So how do you add a code cell? Well, there are a couple of ways to do it. So the one way to do, and by the way, this, what you're looking at here is a code cell, but I'll show you how to create a code cell. You can go to insert, you can click on a cell. So select a particular cell and this one is a text cell.
So then you go insert and insert cell below. So when you do insert cell below that automatically adds a code cell for you. Now, um, You can also change the type of this cell.
You can change from code to Markdown. So Markdown is text basically. Um, and, and then you can type some text and then, uh, What we are going to do is we are going to start running some code cells. So I already have a court cell here. I'm not going to add more.
And here are some simple arithmetic expressions that I've written out two plus three plus nine. And now to execute this code, what I need to do is I need to click the run button. So there's a run button here that you can click. You can also click sell, run sales, or there's a nice keyboard shortcut here. Which is shift plus enter.
So just run shift plus enter, and that will execute and give you the output. Okay. So that's great. So now we are able to add numbers with Python.
Here's a subtraction. Here is a multiplication for multiplication. We use the star sign here is a division here is okay. So a hundred divided by seven Python automatically converts that into a decimal number, even though these are integers and you can see that it's about 14.28. Now, if you just want to get the quotient without the decimal part of it, you know, just get an integer, then you use a double division sign.
So here a hundred by seven, and if you want to see the remainder, then you use this. This is called the percentage or ampersand operator. So this gives you the remainder.
So the remainder is two and the quotient is 14, and we can verify that we can just take the remainder too, and we can add it to 14 times seven and we get a hundred. So you can combine them as well. Another operator that you might want to learn about is the star star operator.
This is the exponential operator. So this simply does five to the power of three, you can try five to the power of five and so on. So as you might expect, this is really simple to just to get started, right?
You write a code cell, you, you, you put some code into a code cell and then you executed and it works and that is valid Python code. So that's great. And as you might expect, you can, these operators have certain precedence by default, but you can also combine them and you can specify the order in which they need to be evaluated by specifying brackets, for instance, here I've put two plus five in a bracket, so that gets executed first, then this, and then these two get multiplied, then that gets divided by four to the power of three. And that's the output.
So that's basic arithmetic with Python. Um, these are the operators that are supported addition, subtraction, multiplication, division, and exponent. And what you can do as an exercise, if you're new to Python, if you're new to programming is just open up some word problems, I've given a link to some simple word problems and try to solve them by adding some formulas here and, uh, just getting the outputs.
Okay. So let's now solve a multi-step problem. And by the way, once again, if you have any questions or if you get stuck, just go back to the forum and post your question on the forum. So let's have a, let's solve a multi-step problem using Python.
So here we have a grocery store that sells a bag of ice for $1, 25 cents and makes a 20% profit on each bag. If it sells 500 bags of ice, how much total profit does it make? Okay. A simple arithmetic problem. You may have seen this in school, probably primary school.
So how we go about it is we define, well, we lay out all the information. So the cost of ice bag is 1.25. The profit margin is 20%. That is 20 by a hundred point.
Two. So the profit per bag is the profit margin times the cost of the ice bag. So then we have this expression and then the number of bags is 500. And then the total profit then is number of bags times the profit per bag.
So finally we end up with this expression. This is the point where you would pick up a calculator. And here we are going to use Python to do it. So the grocery store. makes a profit of $125 total.
Now this is an okay way to use it, but this is not using the full power of Python. And it's not really clear by looking at the code, what these numbers represent. So what we can do is we can actually give names to each of these numbers by creating variables. And variables are interesting concept in a programming language where.
You can take information and put them into these boxes or containers and then give them a name. And so these are called, these boxes are called variables and the information stored in them is called, uh, the variables value. Okay. So here we are now.
So the cost of ice bag is the first variable. It has the value 1.25, $1.25. Then we have the profit margin, another variable. It has the value 0.2.
And finally we have the number of bags. This is 500. Okay. Now, one thing to keep in mind is that I have used underscores because of variables need to be continuous, need to be a single word, and you can break out words using underscores in Python.
If you do not have this, then you will get an error. Okay. So, uh, each variable has a, a single word name, which can contain underscores or let uh, letters or numbers. So now we have the cost of ice pack.
That's great. We have the profit margin. We have the number of bags now in these, in the arithmetic operations, we can start using these.
So for instance, the profit margin, you know, by the way, if you have, this is called declaring a variable. So you put a variable name and then you put an equal to sign and then you put the value. So now the variable has that value to check that value. You just type the name of the variable out and then you can see the value.
Now we have the profit per bag. Now this is a new variable I'm creating and to create this variable, I'm actually going to use an expression and expression that depends on other variables. And this is a nice thing where you can start combining these things together and collect a lot of information. So now you have the cost of ice bag.
So that's 1.25 times the profit margin. So that becomes a profit per bag. Then we have the total profit. So the total profit is the number of bags.
times the profit per bag. And now we can check the total profit. It is 125, right?
So already, this is much nicer where you go through these few lines and you understand what's really being, what's really happening here. Right. And the other good thing is now, if you change the number of bags, like if you have a, on a different day, you have a different number of bags. You can simply reuse the values of these variables.
You do not have to note them down somewhere else. And that's the, that's a great thing about programming. Um, once minor thing here, now a variable has to first be defined using this assignment operation. If it is not defined yet, for instance, I've not defined a variable called net profit and you try to access it.
Then you will get an error. And now don't worry if you get an error in Python in Jupiter, because normally, you know, a lot of programming languages, when you get an error, you have to stop, but in Python, you do not need to stop. In Jupiter, I mean, you do not need to stop.
You can actually just go ahead and change something. Let's say the net profit. I just want to assign it a value of a hundred and run it again and everything will work fine. So that's a great way to just fix things, you know, try out different ideas, break things, and then the more you break, the more you learn. So this is good.
Now we are able to display the total profit $125, but it would be nice to show this. as a message. Uh, and that's what we can do using the print function.
Now what's a function. Now a function is a reusable set of instructions. Just as we are writing some code, we are writing some programs here.
A lot of programs have already been written for the common things that you might want to do. And Python provides a lot of built-in functions. The print function is what we're going to see. And it also allows us to define our own functions.
So here now we have the print function and the way to use a function is to type the name of the function, then open a bracket and then give it some inputs. So here we are giving it a first input. This is some text in English that we wanted to print.
Um, one important thing to note here is that when we're giving it some text in English, any anywhere in Python, we need to use quotations. Because otherwise Python tries to interpret this as code. Uh, but obviously there is nothing inbuilt in Python called grocery.
So this will give you an edit. And that is why we have quotations around anything written in English or any language for that matter, any human language. So that's the first input to print. So we're saying that print this, and then we give it a comma.
And then we say also print the value inside the total. profit variable. All right.
So, and that's the print function you, it takes the snow that prints out the grocery store makes a total profit of $125. So great. That's a, we made good progress already. We started using variables.
We've started using the print function. Um, now one thing that you can do here, because all of these code cells so far, we've just been writing a single line. It can get a little bit tedious and also a little bit confusing when you have all these different, different lines of different code cells.
So Jupiter allows you to write multiple lines of code within a court. So what you can do is you can rewrite the solution to the problem that we saw above. And we can use just a single code cell here. So here we are saying that the cost of the ice pack is 1.25, the profit margin is 0.2. And then we are performing the calculation and then we are displaying the result.
And if I run this, you will see that it prints the exact same result. Now, one interesting thing here to note is that I've actually written some words in English and I said use quotations, but I've not used quotations. Well, that's because this is a comment. So here, what happens is the moment you enter the pound or the hash character, and then maybe give a space after it. So when you enter the hash character inside a code cell, that becomes a comment that is somewhere where you can write.
something that will be ignored by the Python interpreter. So Python will not evaluate it, but this is information that you want to share with somebody who is going to read the code. For instance, I have shared this notebook with you and you can now understand by reading this comment, what this block of code does all right. And this is a very important thing. Um, similarly blank lines are ignored and then this comment is ignored as well.
So comments are a great way to just, this is called documentation. Comments are a great way to just document what you are doing. Okay. And there are a couple of ways. Uh, there are two ways to define comments.
So comments can live on, uh, on the, at the end of a. a code statement comment can have its own line or comments can also span multiple lines. All right. So yeah.
And you can try these out. I will not, this is an exercise for you to try out. I will not go over it in a lot of detail. The next thing that I want to cover is evaluating conditions in Python. Um, and, and we'll just do this very quickly because again, this is pretty straightforward and then we can move on to some more interesting stuff.
So here I have a few variables. Now, if I want to check. I have a variable and maybe I read its value from somewhere.
I'm not quite sure. And if I want to check that it has a certain value or not, or maybe, let's say I want to check if my favorite number is actually equal to one, then Python has the equal to equal to operator. This is called the equality check.
So here you give it something on the left and then something on the right, and it compares the two and returns through the value true. If they are equal. On the other hand, if the two values are not equal, for instance, my favorite number and my least favorite number, not equal, it returns false. Okay. So there's the equal to operator.
And then there are a few of these. So there is the not equal to operator. So this is read as not equals. Then there is the greater than operator.
And then there is the left, there is a less than operator. So for instance, here is the less than operator, my favorite number less than 10. That's true. And my favorite, my least favorite number, which is three.
less than my favorite number, which is one that is false. Okay. Then we also have a greater than equal to operator and a less than equal to operator, right?
The key thing to notice that they return true or false, which are special keywords in Python. So that's operators and just like arithmetic operations, you can re the result of a comparison operation can also be stored in a variable. So for instance, here are the cost of the ice bag is 1.25.
And if I check if the, if the cost of the ice bag is greater than 10, I can put that result into is ice bag expensive. And then I can simply print out that result. Well, so you can see that the ice bag is actually not expensive since the volume, since the value is false. Okay. And operators can be combined.
So sorry, conditions can be combined. Uh, there are three ways, three logical operations to combine conditions. One is the, and operation. So a and B holds true only if both a and B are true.
Otherwise it's false. Then we have the, or operation, the, or operation a or B holds true. If either one or both of A or B are true. And finally you have the not operation.
So not simply takes a condition and then reverses the condition. For instance, my neutral number has the value three. So this condition is true.
And then when you say not, so not true becomes false. All right. Um, so you can play around with this and I, and what I would suggest the way you try this out.
is to actually just go, go to file and then go to new notebook, open up a new Python three notebook. Now take that and put that into one half of your screen and then take the other, take the existing notebook and put that into the other half of the screen. And especially if you're new to Python, if you're new to Jupiter, what you should be doing is you should be looking at the code and typing it out yourself. And this is a great way to learn for, for beginners.
Just type out everything. Do not just do like a shift, enter, shift, enter, shift, enter, so that you just run through everything in 20 minutes and you're done. Now take the time to type things out, take the time to try out experiments. Now you can break things.
What happens if you do this? And I've not defined this. So this is, this is really the best way to just experience what it is like to write this code. Okay. So I will not do that, but this is how I recommend working on all the notebooks.
Start with a blank notebook and just type out the code line by line. All right. So one last thing that I want to cover before we take some questions and move on is that. So far I've been typing some code into these code cells, and then I've been writing some text here.
And this text, if you want to actually, you can actually edit this text as well. If you see that, okay, maybe you need to add some more explanation for yourself. Maybe you want to take notes.
So to edit this text, just double click on this, on the text, and then you can start up editing it. So for instance, I just do this as an edit and then I do shift enter again, and that changes this text, right? Um, one of the nice things about the way text is written in Jupiter is that it uses a formatting style called markdown.
So you can see here, this text actually is a head. And then below here, I have a bunch of different headers and then I have a bulleted list and I have a numbered list. So there's a lot of interesting stuff going on here.
Uh, and it's really easy to create this style like this, right? You're just to organize your notebooks a little better. You can use Markdown and how do you use that? Well, if I just double click, you can see that all I need to do to make my text bigger is to add a couple of pound characters and a space. In a Markdown cell.
And that will make my text big. So if you had one pound character that will make a header and then you can try different sizes of headers with different pound characters to create a bulleted list. All you need to do is leave a space line space, and then use the star character. And then just write the items that will get converted into a bullet. Uh, you can also create a numbered list.
You can also create links. This is a way to create a link. You can also include images. This is a way to include an image. And in fact, you can use include code examples as well.
Now these code examples that are inside the markdown cells will not be executed. They cannot be executed. So it's more for like an explanation or documentation purpose.
So let me just run that and show you. So here's an image and here's the code. So Markdown is very simple. It takes like 20 minutes to learn it.
And it's a really nice way to write pretty text. So you can learn the full syntax of Markdown here. I've linked to a tutorial. Okay.
So that brings us pretty much to the end of our first notebook, our first Jupiter notebook. So we've learned some Python here, basic arithmetic logic conditions. We've learned some, a little bit about the Jupiter interface. Uh, now, as I said, this.
Notebook is running online on a free service called binder. So it's just a place. Is this a website that lets you run Jupyter notebooks online for free?
Um, but this is a, since it's a free service, it's going to shut down after some time. So your notebooks, if you, if. leave the tab, if you go away from it for 10 minutes or something, then this notebook will shut down. So what you can do is whether you're running this notebook online or on your local machine, you can save your work from time to time to your Jovian dot ML account.
So the same account that you used for logging in, all you need to do is run pip install Jovian. This is a command that will install a Jovian Python module, a Python library. It's a, it is what we will need to actually send our notebook, this notebook to your Jovian account. Then we do import Jovian.
Well, that actually imports the library and tells Python that we are now ready to use the library. And finally, there is a function called Jovian.commit. So just as the print. function, we've written a commit function that will take your notebook and that will put it on your Jovian account so that you don't need to do any other steps. So you just say Jovian or commit, and then you give it a project name.
So you just type project equals, and here I'm just going to say Python first steps with Python demo, because I do not want to disturb the actual project that I created. So yeah, so now we have Jovian.com and project, and when you run this, it will ask you for an API key. Well, this is it's it is asking you for an API key so that it knows that you are authenticated.
So to get the API key, just go to Jovian.ml. And if you're not logged in, you can, if you're not logged in, if you're on the website, you can just click sign up or sign in and sign in with Google or GitHub. But once you're logged in, You will see your profile and on your profile, you will see an API key.
So you can copy this API key, just click the button and it will get copied to your clipboard. And then let's come back here and let us just enter the API key. So we'll just show you a bunch of stars or a bunch of, you know, it is hidden. I do not want you to see my API key, but once you press enter, this is then going to take this notebook and then put it online.
So that you can now shut down. Now I can just open up this link, the final link that it gives me, and I can shut this down. So there you go right now.
I'm leaving the site and I'm shutting this down. And now I end up with this page. Similar to the page that we started out with. So this, we have, we have the same Jupiter notebook here, and you can actually take this link and then share it online with other people, just as I did with you. And you can see that the notebook is here, but then there's also, you have all of these options.
You can, if you want to continue running, you can click run on binder and continue running. So this is how we use Jovian. Um, so, and you will be using Jovian to actually work on the assignments and things like that. So that's a quick intro for you. Okay.
So let's take some questions now, and then we will move on to the next topic. I hope you have been posting questions on the assignment thread. Okay. So there's a question is Jovian commit similar to get up, commit. Yeah, pretty much, except it does a commit and push essentially.
So then, okay. So how does Python ask user for a data input where you just use the input function? So thanks.
All right. I don't see any other questions here, so we can just move ahead. So let me just close some of these. Okay.
So we've covered our first steps with Python. Now we're ready to move on to variables and data types. So just click the variables and data types link. Now this is yet another Jupiter notebook.
And this is part two of, let's say the general introduction to programming with Python. Gentle because we're only covering a few topics that we need. Once again, click the run button.
Not right now. Do this after the lecture, go to run and click run on binder. Okay.
So sometimes this might take a couple of minutes or even up to five to 10 minutes to run and that's okay because sometimes. Since this is again, it's a free service. So it takes the, it installs a bunch of libraries for you. It creates a Docker image for you in a Dutch does a whole bunch of things to make sure that you can run things, but it might take a couple of minutes sometimes. Well, you know what?
It seems like I am stuck here, so I'm just going to open up a well, I did click a run just before we started the lecture. Oh, it started. That's okay. Okay. So now we are once again, back on Jupiter.
Once again, this is running online somewhere and we can now open up the second notebook Python variables and data types. Let's just give it a moment to load. There it is.
And the first thing you need to do once again is go to kernel restart and clear output. Okay. You need to do this only if you want to clear out all the outputs that are already calculated. So I just want to restart and clear all the outputs out.
And let me just hide the toolbar so that you can see it better. Okay. So variables, right?
And we know already what variables are. They are containers for storing information for storing data. And the data stored in a variable is called a value.
And this is how you create an access, the value of a variable. So you set my favorite color and then you access my favorite color and a variable is created using this assignment statement that we've already seen. I know that this assignment statement is actually different from the equality comparison operator, which is the equal to equal to operator, which operates on two things on the left and right and returns to you a value true or false, right?
So this is a common mistake that we. often do when we are starting out with programming, unfortunately. Um, you can also define multiple variables on a single line like this comma separated.
So there you see, they have the three values and you can assign the same value to multiple variables by chaining and assignment operation. So for instance, if I write color six equals magenta, then I can say color five equals. That, and then I can see color four equals that. So that change these operations and each of them. gets the same value.
So that's how you create variables. Now in Python, any, you can change the value stored in a variable simply by assigning a new value to it. Right.
So we have defined my favorite color, which has the value. Well, we, which has a value blue. Actually we can. Yeah.
So which has the value blue. Now, if I redefine or reassign the value red to my favorite color, you can see that the value blue has gone away. The value blue is lost and no longer accessible.
And now the value has become red. So this is important that when you reassign a variable, the old value is lost, gone. So be careful. What you can also do, and this is again, interesting is that while reassigning a new value, you can use the old value of the variable as an input to the, to the expression, which is used to assign the value.
For instance, counter equals 10. And then we are saying counter equals counter plus one. Now, normally in math, you would cancel these out and this would end up with zero equals one. This is not what we can do here because this is assignment.
So counter plus one. They come. comes 10 plus one and that gets put into counter. So counter has the value 11, right?
And since this is such a common pattern, Python actually has no, whenever you're doing the variable equals variable, then operator something, you can also write it like this, so counter equals 10. And now we do counter plus equals four. That's the same as counter equals counter plus four. All right.
So that's your, so this is how you create variables. Now a quick note on naming variables, variable names can be short, like a single character, a X, Y, or they can be long, like my favorite color profit margin, the three musketeers. But there are a few rules you have to follow while naming Python variables.
A variables name has to start with a letter or the underscore character. It cannot start with a number. That's the first one. A variable name can only contain lowercase letters. lowercase and uppercase letters.
So A to Z lowercase or uppercase, it can contain digits except at the first position and it can contain underscore characters, right? And then finally variable names are case sensitive. So all variable well with all lowercase is different from all variable with A and V in uppercase, and that is different from a variable. So these are all different variables with different values. All right.
So just be, just be aware of that while creating variables. So here are some valid legal variable names. And below, uh, what you can see here, these are some invalid variables that I've created.
So here we have a space that causes a problem here. We have a special character that causes a problem here. We have the hyphen Python actually reads this as a minus. So it tries to subtract these three variables.
So, but they don't exist and that's why there's an issue. And finally, here we are trying to use a number as a starting, you cannot start a variable with a number. Okay. So that's, that's how you, that's all we wanted to talk about variables.
No, it's a very simple concept. Python makes it really easy to use them. And at this point, what we'll do from now on is after every section, just record our work.
So I'm just installing the Jovian library and I'm running Jovian.com. It for every Jupiter notebook that you run online, you will have to enter the API API key, but just once, not more than once. All right.
So that's, that's committed now. Now, any data that you store inside a Python variable has a type. So, so far we've been working mainly with numbers, but there is a lot of different types of data that you can store within a Python variable and a variable. Type can be checked using the type function. For instance, a variable has the value 23 and it's type.
If you use the type function, it's type is int. Int stands for integer. Similarly is today Saturday. It's false.
It's type is bool. It stands for Boolean. My favorite car is some text and it it's type is STR, which stands for string. And finally the three musketeers, it looked like it was like a list of three strings.
So it has the type list. All right. And Python has a several built-in data types for storing different types of information into variables.
So what we will look at are some of the most commonly used data types. Um, now there are a few primitive data types or what are called the smallest units. So integers, floats, Booleans, none, and string, all of these are called primitive data types. And then you have these other types like list.
Dupil dictionary, and then you have sets and classes and so on. These are called data structures or containers because they hold multiple pieces of data together. Right.
And each piece of data then has its own type. So that's a key distinction. So let's start, let's start by looking at integers then. Well, we've been working with them. We know what they are.
They represent positive or negative whole numbers. So from negative infinity to infinity, only thing to note is that they should not include any decimal points. So here's an integer and it has the type int as we've already seen now, unlike. Other programming languages like C C plus plus in Java, where you may have different types of integers, there is no such limitations on what is the lowest or highest value an integer can hold in Python, all integers are arbitrarily large.
Right? So here you see a large negative number. It is quite arbitrary, really large. And it still has the type int, there's no long, long. or something like that.
And that's integers pretty straightforward. Then we have floats or floating point numbers. So these are basically numbers with a decimal point.
Again, there is no limit on the value of the float. Although what will happen is some kind of approximation might happen depending on where the, depending on how many characters decimals you put in. So they are a little bit limited compared to integers for sure.
So here I'm looking at the value of PI by the character, the, mathematical constant, I put in 3.14 and so on, and then I can check its value. And you can see here that it actually truncated the value around a well around about, I don't know, 15 or 20 decimals. So there is a limitation in floats there.
Okay. And then if you check the type of pie that turns out to be a float. And one important distinction here that we often tend to miss is that even a whole number is treated as a float. If it is written with a decimal point, for instance, here we have a number which I've written as 3.0. Well, That's a float because there's a decimal there.
And similarly, there is, um, even if I do not have something after the decimal, even if there's just a decimal that is also treated as a float. Okay. So just know that sometimes that trips people.
pull up a little bit, and then there's another way to write a floating point numbers. If you do not, let's say you have a very small number, which 0.5 zeros, and then a one. Well, the way you can write that, let's say if you want to do 0.0, 0, 0, 0, 1, you do one E minus five. So that E minus five basically converts gets converted to 10 to the 10 raised to the power minus five. And that gets multiplied with this number.
But I just do one E minus two and you can see it has the value 0.01. Here's another one here. I'm using a positive exponent.
So here, this is the Avogadro number. So here at 6.0, two, two times 10 to the power 23. And there you go. So that is the Avogadro number. All right. So that's, that's pretty much eight about floats again, pretty straightforward and floats can be converted to integers and vice versa.
Uh, so the way to do it is using the float and int functions. Uh, and so the types. that we see, these are actually functions that you can use.
So the float function, if you pass it in integer, let's say float current year, or it had the value 2020. So now that becomes 2020.0 or float times a large negative number. Well, a large. Let's see what that value is.
So what I'm doing here is I am actually going to insert a code cell. The way I could do it is say insert and insert cell below, or I can simply just. Click escape, press escape plus B and that will insert a code cell.
Okay. So let's just type the name of a variable. And again, what you saw here was that I simply typed a. underscore L and then I typed the, I pressed the tab character, the tab key, and that automatically completes to a variable name. So that's one nice thing about Jupiter.
Uh, so you see here, it's a large negative number. We can convert it into a float. So when you convert it into a float, some precision is lost, but now you can see that it's written in scientific notation. Uh, similarly, we can convert in the PI, the value PI to, uh, integer.
So PI was 3.14. When you convert a float into an integer that the part after the decimal gets removed, right? So even if you're at 1.99 and you convert it to int that gives you back a one.
So that can be a little unexpected sometimes. And finally, here we are taking the Avogadro number and converting it into a integer. Okay.
Now, when we perform arithmetic operations, what happens is if, if all the operations are integers, generally speaking, the result is also an integer, but if any of the, if any of the operators, if any of the thing. numbers that you're operating upon is a float, then the result gets converted into a float. So for instance, 45 times 3.0 is a float, but 45 times three is an ink. Now one exception is the division operator. The division operator always returns a float.
Because there's no way to know in advance, whether there is going to be a decimal point or not. So just to be consistent, it always returns a float, whether it's 3.33 or whether it's 5.0. And if you want to get back an integer, if you know for sure that the division that you.
doing will result in an integer. You simply use the double division. This is also called the integer division operator and that returns an integer.
Okay. So that's floats pretty straightforward. Then we have Boolean's we.
We've already seen these bullions are the results of conditions essentially, and they have. So the Boolean type has exactly two values, true and false. There's no other value there floats that are unlimited integers that are unlimited, but bullions are just these.
And bullions have the type bool. So if you check the type of a boolean, it's true. It's a bool.
So here I'm setting is today Sunday to true. Well, in some parts of the world it is. And, then I just check the type of is today. Yeah, this should say yesterday, Sunday. Yeah.
Just check the type of history Sunday. And that turns out to be a bull. That's how you declare a Boolean.
It could also have been a condition. So let's say this could have been two less than three and it is still true. But let me revert that. And Booleans are generally returned as a result of a comparison operator. So for instance, here I have the cost of an ice bag is 1.25 and I have the comparison, whether it's greater than 10. So now the result of the variable ice bag is ice bag expensive becomes a Boolean, uh, is holding a Boolean value, right?
You can check that with the type. And an interesting thing is that Booleans are automatically converted to integers. When they are using arithmetic operations.
So for instance, well, you, what you will notice is true gets converted to one and false gets converted to zero. So it's, it's useful that if you have, let's say a bunch of bullions and then you want to just add them together. to just see how many truths there are, how many falses there are.
You can simply add them as integers, right? So if I do for five plus false five gets converted into the integer zero. So we end up with five and if I do three plus true and here.
here I'm doing three dots. So first true gets converted to the integer one. Then since you're adding an integer and a float that gets converted into a float and you end up with a float 4.0. Okay.
So that's something to keep in mind. Um, another very, very useful thing is that any value in Python can be converted to a Boolean using the bool function. So you just use the bull function, put in anything, anything that you write in Python. Well, any value or any expression, technically speaking, that expression will get converted into a Boolean. Now, how now, when it gets converted into a Boolean, how do we, how does Python decide whether it should be a true or a false?
So the way to do that is that there is only a limited number of things that become false. So the value false itself is false. And then all the empty states. All the different data types, all the sort of the zero states, you can say of the different data types, they get converted to false as well.
So you have the integer zero that gets converted to false. You have the float 0.0 is false. Then the empty value, none, we will see it.
That gets. converted to false, the empty text, the empty list, the empty tuple, empty dictionary, empty set in range. So all of these get converted to false automatically. And we will see how this is useful later when we learn about if statements.
Uh, so these are some examples of false, and then here, these are other examples of values that are converted to true. So these are called. The values that become false are often called falsy values. And the values that become true are often called truthy values.
So it's also called falsiness and truthiness of those values. So that's Boolean's pretty again, nothing special happening yet. Next we have the none type. So the none type has a single value called none. And it is used to indicate the absence of a value, right?
If you want to declare a variable, let's say, which may be assigned some value later on, or because of some reason you want to indicate that a value is missing, but you still have to, let's say, set a variable. Then you can simply set it to none. Okay. Then this is nice to have that type so that you don't have to use zero as a fill-in or use false as a fill-in, which you have to do in other languages. So you just say variable name equals none, and that sets it to none.
And it has the non type type. Okay. Not nothing much going on there.
Finally, the last primitive data type is a string. So a string is used to represent text in Python. Why is it called string? Well, you can think of it like a string of characters, you know, a character is tied together with a string, the sequence of characters, uh, and strings in Python must be surrounded using quotations. And you can use either the single quote or the double quote and strings have the type string S T R I N G. Um, so here let's create a string today and it has a type STR oops.
Well, I guess this is an error. They should just say STR. And now you can know, so that was one example. Now, as he mentioned, you can use either single quotes or double quotes to create a string.
So, and then, you know, what might happen is that the text that you want to write itself may have single or double quotes. So just be careful. about that, you know, if you're creating a string with a single code and there is a single code inside, for instance, one flew over the cuckoo's nest.
Um, now what happens here is the string ends here and then Python starts to execute this as proper Python code. And then it's going to show you an error. Okay.
It says invalid syntax. So this is where, what you might want to do one technique is to just add a slash. This is the other slash that is above your enter or return key. So just add a slash.
What this does is this escapes the next character so that it is not treated as a closing quotation mark. Right. Okay.
And the slash won't show up when you actually print it. That is one way to check it. So you can see here, it says one flew over the cuckoo's nest.
So we have escaped the court. The other way is to simply use. A double quotations when you have single quotations in your string and single quotations, when you have double quotations in your string, okay. Uh, and you know, there are some more examples here.
I will let you figure, I will let you play, play around with these. Now you may have a lot of questions. What do, what happens if I have both double and single quotes? What happens if I have to break my string into multiple lines?
I can't fit it on a line. All these things, Jupiter is a great way to try them out. So the way you should try it is first, try something. Try what you think might be the solution and run it and then get an error. And then maybe look up online or maybe just take the error and Google it, or maybe just post that error on the forum and then somebody answers it.
And then you will learn how to actually do it. And once you do that, you will retain it better. Okay.
So there are some examples of different types of strings. You can also create strings that span multiple lines. So for instance, here, this is a string that goes over four or five lines. The way to do that is to use three quotations. That's a special three quotations is a special marker in Python.
Um, then yeah, so, so that's our multi-line string and you can experiment with these parts. I'm going to leave it up to you. Um, but what's interesting is now already with string, you know, even if, even though it's a primary data type, it actually does contain a bunch of characters. So it's kind of a container as well.
Um, so you can actually check the length of a string using the length function. You can check how many characters. So for instance, length of my favorite movie, one flew over the cuckoo's nest is 31. Um, and then there is, there are some special characters.
So for instance, the slash end character represents a new line and then there are escaped characters. So these special characters are escaped characters are actually counted as a single character. Often. So for instance, here, I have a multi-line string where I start the string, then I have a, and then I have a enter. So now, This enter is actually a character in Python because of Python stores the enter or the new line as a character.
This is the slash and character. Then we have a B. So in total, there are three characters here, right? And you can see that sometimes it gets printed like this.
So we have a, and then we have slash in, and then we have B. And if you check the length that turns out to be three. So that's good. We know how to check the length of a string. If you want to actually take the string and then convert it into a list.
So a list is a different data type that we will see soon. If you want to convert it into a list, you can just pass it into the list function. And now that gives you a list of all the characters, all treated separately. Now. If you want to access individual characters in a string, you can do that as well.
So today I have set to Saturday and now if I want to access the, so the way to access characters is to type the name of the variable and then type a square bracket and inside the square bracket, use an index. So the characters are indexed from zero to N minus one, where N is the length of the string. So you have zero one, two, three, four, five, six, seven, eight, nine, or I think this goes up to seven. So zero is S today.
Three is zero one, two, three U and then today seven is the last character. All right. Um, and you can also access a part of the string by using the well, by providing a start index and an end index. So for instance, we are saying five to eight here. So, So we go from one to three, four, zero one, two, three, four, five.
So that's D six, seven. And then the last index is actually not taken, right? So we do not use the last index. So we, we go from five, six, seven, and skip eight.
That's just the, that's just how ranges work in Python. So that's how you get something out of a string. You can also check whether something is in a string. You can check whether a string contains something using the in operator. So we can check day in today.
That's true. We can check sun in today. That's false because today is, it says Saturday.
And you can join strings. So with, as, as our data types get more complex, you need, there are a lot of operations you may want to perform upon them, right? So there are operators and then there are also a lot of other things you can do.
So here I have a full name, which is Derek O'Brien. And then I have a greeting, which says, hello. I'm just going to say greeting plus full name. What this will do is this will take these characters and take these characters and combine them into a single string.
So it says hello, Derek O'Brien, but there's one issue here, and this is a common thing that we, that we often end up doing. So just be careful about this, especially while you're doing the assignment. Some sometimes when you are combining strings using the plus character, then.
Sorry about that. I think we may have gotten disconnected for a second. Let me just verify that everything's running fine. Okay.
I guess we're okay. So strings in Python have a bunch of built in methods and these methods can be used to manipulate strings. So let's try out some common string methods. But by the way, what's the method? A method is simply a function associated with a data type.
And we've seen what functions are. They take an input and then they perform some operations on the input. Yeah.
So they take an input and then they perform some operations on the input and then they may be give out output. So those are functions. Uh, similar.