Learn Python for Data Science – Full Course for Beginners

freeCodeCamp.org · Beginner ·📊 Data Analytics & Business Intelligence ·1y ago

Key Takeaways

The video covers the basics of Python for data science, including essential tools like Pandas, NumPy, and Jupyter Notebook, as well as data visualization, cleaning, and machine learning techniques.

Full Transcript

Get started with data science using Python. This course covers essential tools like Pandis and NumPy, plus data visualization, cleaning, and machine learning techniques. Perfect for beginners. You'll gain the skills to analyze and interpret data effectively. Frank Andrade created this course. This is my Python for data science course for beginners. In this course, you'll learn everything you need. Pandas, Numpy, visualizations, data cleaning, machine learning, and more. In this course, I not only teach you how to use Python for data science, but we also solve many exercises and work on four projects to put into practice everything we learn. I leave the link to the code and my Python cheat sheet I created for this course in the description of this video. In my cheat sheet, you'll find all the concepts we learn in this course, as well as code snippets that you can use for solving exercises and projects. All right, now let's start with this course. Anaconda is all about data science. It brings all the tools used in data science like Python, Jupiter notebook and pandas with just one installed. And in this video, I'll show you how to easily set up Anaconda on your computer. So to download Anaconda, we go to anaconda.com and click on get started. Then we choose the last option, download Anacon installers. And then we have here the different anacon installers. So there are Windows, Mac and Linux. So in my case I'm going to choose Mac and I'm going to choose the 64bit graphical installer. So now I'm downloaded Anaconda and once it's downloaded I'm going to click on it and a message will pop up. You just have to click on allow as I'm going to do right now. So just click on allow and then click on continue until the installation starts. So I just click continue and then agree and then continue and it's going to start installing Anaconda. In case you're on Windows and you're installing Python or Anaconda for the first time, make sure to check the first box you see now on screen. So I'm going to speed up the video now. Okay, the installation is almost done and now it's telling me that an account that works with PyCharm and now I'm just going to click on continue to finish the installation. So I click on continue and then we'll see just a summary of what was installed. And now I'm going to close this window and I'm going to open Anaconda. So I'm going to locate the icon. It's a green icon. uh this one that you see here and I'm going to open Anaconda. I'm going to wait a couple of seconds and let's see what was installed. So here we have the Jupyter Lab and Jupyter Notebook which are widely used in data science. So I'm going to launch Jupyter Notebook. So here it's opening Jupyter Notebook. Let's give it a second. And now we open a new notebook with Python 3. So, Python 3 was installed too. And here I'm going to import pandas. So, I write import pandas as pd. And if the code runs fine, then the installation was successful. So, let's wait a couple of seconds. And now, as you can see, it's working. So, I can create a data frame without any problem. So, now let's go back to Anaconda to see if Jupyter Lab is working fine too. So here is Jupyter Lab and I press on launch and just wait a couple of seconds and now Jupyter Lab is open. So here is the file I was using before and it has the data frame and everything is fine. Finally let's see how to install a new library. So we go to environments and on the right side there is a search box where you can write any library you want to install. So here I'm going to check if pandas is installed. So you can see pandas and then there is also numpy and scikitlearn. And if you want to install a new library you just have to click on the dropdown and choose the option non-installed. By the way you can install a new environment using the Anaconda navigator. You just click on this create button and then you will see this window and here you just have to write the name of the environment and choose the Python version you want to install in this environment and that's it. Now you can start working in your data science project. In this video I will introduce you to the Jupyter Notebook interface. Jupyter Notebook is an open-source web application that allows us to create and share documents that contain live code, equations, visualizations, and text. This is the perfect text editor for doing data cleaning and transformation, data visualization, and data analysis. This is why Jupyter Notebook is widely used in data science and also machine learning. As you might remember, we installed Jupyter Notebook and Python with the Anaconda Navigator. And this means that we already have installed some popular libraries used in Python for data analysis. By the way, one of the alternatives of Jupyter Notebook is Jupyter Lab. Both are similar, but we're going to use Jupyter Notebook in this course because of its simplicity. So, let's open Jupyter Notebook. And to do that, we have to click here on the launch button. So I click here. And now we wait a couple of seconds. And now we have here the interface of Jupyter Notebook. So I'm going to maximize this. And by default, Jupyter Notebook opens the root directory of your computer. It's a good idea to create a folder where all your Python scripts will be located. In my case, this folder is called Anacon scripts. So, I click here and now I can navigate through the folders. And the folder I'm going to use for this example is this one that says my course. And here we're going to create our first Python script. To do that, we click here on the new button. So, click here. And we have to click on the first option that says Python 3. There are other options like text file folder or the terminal, but we're not going to use these options in this course. So click on Python 3 and now we have a Python script powered by Jupiter notebook. So here on the right you can see that it says Python 3 and also there is the Python logo and on the left you can see here the Jupyter notebook logo and also the name of this Jupyter notebook file. We can change the name of the file by clicking here on untitle. So I click here and I can change it to let's say example. So I write example and I click on rename. And now we rename this Jupyter notebook file. All right. Now let's navigate through this menu bar that we have here in this Jupyter notebook file. So the first option is the file. In here we can create a new notebook with Python 3. So if we click here, we're going to open a new Jupyter notebook file from scratch as we did before. Then we have that open. And in this case, we can open a Jupyter notebook we created before. We can also make a copy to a Jupyter notebook and then change the name. We can save a Jupyter notebook file and rename the file as we did before. We only click here and rename the file. Then we can save all the progress we make in Jupyter notebook. For example, after writing many lines of code, you can save all the progress you make by pressing control S or command S on Mac and you're going to create a checkpoint and later you can revert to a previous checkpoint by using this option here. So here you will see many checkpoints and you can revert to a previous checkpoint. By the way, by default, Jupyter Notebook makes saves every 30 seconds or maybe 1 minute. So there is no need to press Ctrl S every time. So keep that in mind. Then we have other options that I don't use so much like print this Jupyter notebook or export that Jupyter notebook file to HTML or PDF and so on. Okay. Now let's see the second option that says edit. And here we can edit all the cells we have here in this Jupyter notebook. By the way, here what you see here on the screen is a cell. So we can edit with this edit option. For example, we can cut cells, we can copy cells, paste cells above and delete cells. On the right, you can see the shortcuts that we're going to see on the next video in detail. And well you can check all the edit options that you can perform on Jupyter notebook here. Then in the view option we can toggle the header the toolbar and also line numbers. So here if I click on toggle header the header is going to disappear. And if I click on toggle toolbar this toolbar disappears too. Also here in toggle line numbers we can show here line numbers. So if I write anything, we can see that it says 1 2 3 and so on. And I'm not going to use this for this course. I'm going to leave it with the default options. So here I'm going to revert to the original option. So without line numbers and I want to show the header and also the toolbar, but you can personalize it as you want. Next, in the insert options, we can insert cells above or below. We only click here. And well, we're going to see the shortcuts later in the next video. Then we have the cell options. We can run cells or run all the cells in this Jupyter notebook file. And then we have the kernel option. And a kernel is a computational engine that executes the code contained in a notebook document. When we open Jupyter notebook, a kernel is automatically launched. And we can interrupt this kernel by clicking here. So by interrupting we can pause the execution of a code. We can also restart everything and do more things here. Sometimes for example I interrupt the kernel when a line of code or a cell takes too much time to execute. And well you can do the same here with restart or interrupt. Then we have the navigate option that doesn't actually have anything here. widgets that I don't use so much and well help that I think it will send you to the documentation of Jupyter notebook and you can read it if you want. All right, here then we have the toolbar and here you will find some shortcuts of the menu bar that we've seen before. For example, here you can save and make a checkpoint. So here I click here and as you can see here it says checkpoint created or something like that. Yeah, checkpoint created and the time that it was created. Then you can here with this plus button insert a cell below. So I click here and as you can see we can insert a cell below and also you can use shortcuts but that I'm going to show you in the next video. Then we can cut selected cells with this button. We can copy a cell with this button. And also we can paste cells below. Also we can move a cell above or below. For example, I'm going to write anything here. And this cell I can move it above with this button or below as you can see here. Then we can run this code. For example, I can write the number one and then run the code. And as you can see here, the code could ran and it shows the number one. And well, those are some of the frequently used buttons in the toolbar. And that's everything you need to know about this Jupyter notebook file. Okay. Now, before finishing this video, I'm going to show you some other options that you can find here in the Jupyter Notebook interface. And here you can see that there are some other options. So, right now we are in the files tab. And we can change to the running tab here. And here you can see all the currently running Jupyter notebook processes. For example, we can see here the Jupyter notebook file we created and that we opened. So you can recognize that a Jupyter notebook file is open or that is running because here the icon will be in green. So here if we go back to the files tab we can see that this Jupyter notebook file which by the way has the IP Y andB extension is in green. So the icon is in green. So this indicates that the file is running and well it was opened. So here we can see that is open and we can shut down this file. And this is different from closing this file. For example, here I have the file and if I close this file here we can see that the file is still running. Here we see running and it's in green and in the running tab it still shows up. So if we want to shut down this file, we click here and it says that there are no notebooks running and we can see here that the notebook has a gray icon. All right. Then we have the clusters tab. And this tab I don't use so much and actually it doesn't show anything here. And then we have the NB extensions tab. Here you can install any extension to personalize Jupyter Notebook even more. And we're going to see some cool Jupyter Notebook extensions in the next videos. And by the way, this NB extensions tab doesn't show up in some versions of Jupyter Notebook, but we can easily install it. And we'll also see how to install this NB extensions tab in the next videos. Finally, we have this box that shows our directory. So here this folder indicates the root directory. So if I click here, we are not in the root. And if I click on the folders anaconda script and then my course, I go to the folder where I was before. And that's it. These are all the things you need to know about the Jupyter Notebook interface. Okay, in this video we're going to see some cell types and cell modes in Jupyter Notebook. So first we're going to open the Jupyter Notebook file that we created in the previous video which is this one example ipynb. So we click on it and here we have the Jupyter notebook file opened and here by default we have this first result in command mode and we can say that this is command mode because here this blue color indicates that the cell is in command mode and when we are in command mode we can do things outside the scope of any individual cell. So basically all the tools we see here in the toolbar we can apply it in command mode. Also in command mode we can apply some shortcuts that I'm going to show you later. And for example if we want to see the shortcut window we press the letter H in command mode and we can see the keyboard shortcuts here. So here you can see all the shortcuts and all the shortcuts that you can apply in command mode. Now I'm going to close this one and also you can apply different shortcuts like for example if you press B in the command mode you will see that there is a new cell because B is the shortcut that introduces a new cell below. Now if we press enter you're going to see that the color is going to change to green. So here we have green color and this green color indicates that we are in edit mode and the edit mode is for all the actions you will usually perform in the context of the cell. For example, introducing text or writing code. So here I can write say 1, two, three. So if I write one, two, three and then I click on this run button, I'm going to run this cell. And as you can see here, I run this first cell. And also after running the cell, you can see that we are again in command mode. So to go to edit mode, we press enter again. And now we can edit the numbers we introduced. So for example, I can write four, five, six, and then run again. And here you can see that the output shows one, two, three, four, five, and six. By the way, if you try to use the shortcut in edit mode, it won't work. Here, I press enter. And now I'm on edit mode. And if I press the letter H, you can see that nothing happens. We don't have the shortcut window. And if I press the letter B, you can see that we don't insert any cell below. This happens because those shortcuts work only on command mode. So to escape this edit mode, we have to press the escape button. So I press escape and now I'm again in command mode. So if I press H, we have here the keyboard shortcut. And if I press B, you can see that we inserted a new cell. And that's it for the command and the edit mode. Now we'll see the cell types in Jupyter notebook. In Jupyter notebook there are three main cell types and we can see all of them in this dropdown here. Right now the type of this cell is code. So here it says code but if we press here you can see other cell types like markdown and row NB convert. So we're going to see first the code cell and it already has the check. So this one is a code cell. So now I press here and now well it's in code cell. If I press enter, I'm in edit mode. And here I can introduce any code I want. So here I can write uh any number 999. And if I press control enter, we can see that here this is the input. And here we got the output of this code. We're going to see how the code cell works throughout this course. But now it's time to see how the markdown cell works in Jupyter notebook. So here I'm going to this cell. And now I'm going to change the cell type. So I press here in the dropdown and now I select markdown. In the markdown cell we can introduce any type of text we want. For example we can introduce titles. So if I uh delete this and press the hash sign we can get title. So one hash it means title. So here I press space and now I write title. Now I press Ctrl enter or this run button to run this cell. And here we got the title. By the way, you shouldn't get this wrong number because I just modify the default behavior of Jupyter Notebook. So mine enumerates the titles and subtitles. But in your case, you will see only the word title. And if you want, you can introduce also subtitles here. So for example, I'm going to insert a new cell with this button. this plus button. And now I'm going to move this cell up with this button here. So I press this. And now I'm going to change the cell type from code cell to markdown cell. So I go to the dropdown and select markdown. And by the way, you can change the cell type also with shortcuts. So if you're in command mode, you can press the Y button to change to code cell. So I press the Y button and as you can see here it says in and this in with the square brackets indicates that this is a code cell. So here I can press enter and introduce any code. Here I introduce numbers and press the run button and here you can see that we have an input and an output. So this is a code cell. But now we can press the M button to make this cell a markdown cell. So now we press M. And here we are in command mode. So now we can get this markdown cell. And here you don't see the in word with a square brackets anymore. So now I'm going to edit mode. So I just press here or well you can press enter to go to edit mode. And now to introduce a subtitle I'm going to write double hash sign. So I press hash sign twice. Now a space. And now I'm going to write the subtitle. So I write subtitle. I press Ctrl enter or the run button to run this cell. And we got here the subtitle. And we can also introduce text. So I'm going to introduce a new cell with a plus button. And you can also do it with a B shortcut. So I'm going to do it with a B shortcut. Right now I press B. And here I got this new cell. And we can move this with this button here. And now we have this cell in the position we want it. So here I can introduce text by converting this cell to markdown. So here I choose markdown. Now I press enter to go to edit mode. And here I can introduce any text. For example I can write hello. I press Ctrl enter. And now we can see that we have here this text. And finally the last type of cell is the row NB convert. And this type of cell is not evaluated by the notebook kernel. So if we convert this code cell to a row cell, this cell won't be evaluated by the notebook kernel. So let's try here. I press row and be convert. Now we can see that this looks like a plain cell. Well, this type of cell is not used that often. Actually, we're going to use only the code cell and the markdown cell in this course. And that's it. In this video, you'll learn the cell types and cell modes in Jupyter Notebook. Okay. In this video, we're going to see some common shortcuts used in Jupyter Notebook. And we're going to start with the F shortcut. And by the way, to use these shortcuts, you have to make sure you're in the command mode. And to verify you're in the command mode, make sure that the cell has this blue color. Okay. Now that you're in the command mode, you can press the letter F. and you're going to see this find and replace. So this first shortcut allows us to find a word in a cell and then replace it with another word. For example, I can write here the word hello. And here it found the word hello inside this hello world sentence. And now I can replace this word with the word say hi for example. So here I write hi. And now in red we can see the match. And in green we can see the word that we're going to insert. So here let's click on replace all. And now you can see that it doesn't say hello world anymore but now it says hi world. So now I press ctrl enter which is another shortcut to run the cell. So you can press here on run or only press ctrl enter to run this cell. So I press Ctrl enter and now we run this cell. And another way to run cells is to press shift enter. But in this case we're going to run and insert a new cell below. So now let's see. I press shift enter. And out here it ran this cell because now it says in and three inside square brackets. And here we can see that we have a new cell. Okay. Now, another shortcut that is often used is the Y and M shortcut. So, now this cell is a code cell. And if we want to make this a markdown cell, we only have to press the M letter. So, we press M and this is going to be converted to a markdown cell. And if we press the letter Y, this is going to be converted to a code cell. And also, you can change the heading here. You can make the heading bigger or smaller. So here I'm going to locate this cell. And now to make this one smaller, we can press the numbers. So if we press the number two, we can see that this one gets smaller. And if I press number three, the title gets smaller for smaller and so on. So as you can see, the more hash signs, the smaller the text. So here I'm going to delete this hash signs and one hash sign represents the biggest font size which is the title. So now I press Ctrl enter and now we have this in heading one. But if I press number five and then press Ctrl enter we can see that now this cell has heading five and it's smaller. So now I'm going to revert to heading one. So I press one and then Ctrl enter. Okay. Now we can navigate through the cells by pressing on the up or down keys on our keyboard. And as you can see here, we can navigate through all the cells here. Or we can also press with the mouse. We can press on the cells we want. Okay. Now we can insert a new cell above by pressing the A key. So if I press A, we get here a new cell above. And if I press now B, we get a new cell below. Now if I press X, we're going to cut this cell. So I press X and you can see that the cell was cat. And now if we press V, we paste that cell below. So I press V and now we got this cell. And if I press shift + V, we get the cell pasteed above. So I press shift and V and we get this new cell above this cell I have here. Okay. Okay, now I can delete cells by pressing D twice. So I press D two times and as you can see here the title disappeared. So now I try it again and we don't have the title anymore. But now if we press the letter Z, we can undo those changes. So let's undo what we did before. I press Z and we get here the title back. Okay, another useful shortcut is that Ctrl S that allows us to save the changes we made in this Jupyter notebook file. So I press Ctrl S and you can see here that says checkpoint created. So I'm going to press again Ctrl S. And here it says checkpoint created and here also says the time. And that's it. These are some of the most common shortcuts used in Jupyter Notebook. But you can see other shortcuts by pressing the letter H. So I press H and here you can see more keyboard shortcuts or you can also go here to help and then go to keyboard shortcuts here and you get the same window. So here you can see a list of shortcuts for command mode and also for the edit mode. You can see the description of a shortcut and also how to do it in your operating system. One of the typical ways to get started with a programming language like Python is printing a simple message. You can write any message you want, but it's traditional among coders to start with a hello world. So let's try it. Let's print our first message using the print function. The print function prints a message to the screen. So I'm going to write here print and then I'm going to open parenthesis. Every time we use a function in Python, we have to open parenthesis. Well, in this case for the print function. And as you can see here, the functions get a green color in Jupyter notebook. So that's how you can identify them. So inside this parenthesis, I'm going to write the message. So in this case it's going to be hello world. So this is our first message. Now to execute this first line of code we have to press control and enter or command and enter if you're on Mac. So I'm going to press this. And as you can see here we have our first hello world. Another way to run this first cell is pressing here on the run button. It's going to have the same effect. So I pressed and it ran. So as you can see here it says in which it represents a code cell and this is a markdown cell as we've seen before. One of the advantages that Jupyter notebook has is that it allows us to print the last object in a code cell without specifying the print function. So for example here I can print this hello world without uh writing this print function. So I'm going to copy this hello world message that it's uh inside quotes and I'm going to run this code. So just controll enter and as you can see here we have this message printed. So this is one of the advantages that has Jupiter notebook. If you do this in another Python IDE it won't work. So here you can try yourself. You can write any message you want apart from the first hello world. You can try with your name. So we write print then parenthesis and we open quotes because uh we need to define a string. I'm going to tell you about strings a little bit later but just so you know right now and here for example I can write my name. So my name is Frank and I can print my name. Then I can print also numbers. So I print my age 26 and it's going to work too. And besides writing code, you can also add comments. Comments are a useful way to describe what we're doing in our code. So here we can use comments. We just have to write the hash sign which is this one. So you write hash sign and then you write the comment. In this case, I'm going to write my name and I'm going to say printing my name. So we know what our code is doing here in the first message we wrote. We can also add a comment. So we write hash sign and then we can say printing my first message. As you can see here the comments also have a different color. So so far we have three colors. This color for the comments uh green color for the functions and red color for the string. This is just a useful functionality most text editor have that allows us easily read code it now. And now I'm going to write any message. So I'm going to write uh for example again uh hello world and again to verify the type we can use the type function parentheses run this code and we got the str that represents a string. And one cool thing a string has is methods. We can apply different functions to strings as we will do in Microsoft Excel for example. However, in Python, we use methods. A method is a function that belongs to an object. To call a method, we use the dot sign after the object. Let's see some string methods to change the case of the text. So here I'm going to write again hello world but now I'm going to use some string method. So I write hello world and in this case I'm going to use the upper method to make this uppercase. So I'm going to use the print function. But actually we don't need to use the print function because as I told you before uh in Jupyter notebook we don't need to use the print because it automatically prints the last line of code. So since this is the only uh line of code in this cell block it's going to print it automatically. So we just run this uh cell and we have hello world in upper case. So as you might expect now we can also change the case of the text. In this case it can be on lower case or title case. So I'm going to just copy and paste this twice. And here I'm going to write instead of upper I'm going to use lower and then title. So you can see how it's going to change the case. So here I'm going to run and let's see what happens. So as you can see here it only printed the last one uh because as I told you before it only prints the last one. And if we want to print the three of them we have two options. So we can maybe here cut and paste on each cell or what we can do is to print each of them. So here for example I can do print here and I can do the same for them. So instead of using more cells we can print all of them. And here we can print this one too. Actually, we don't need them. We don't need it because it's going to print the last line. But just for the sake of this video, I'm going to print the three of them. So here, I'm going to run this code. And as you can see here, the first it has an uppercase, the second has lower case, and the third has a title case. So that's how you do it on Python. Other string method that you can find Python is the count method. So I'm going to delete this and actually this one too. And we're going to see this now. So first I copy this and now I paste it here. And here I'm going to use the count. So the count method. So I write count. And then here I open uh single quotes and I write the letter that we want to count. So here for example I'm going to write the L letter. And what this uh string method is going to do it's going to count how many times this L letter is included in this string. So as we can see there are two L's. So it should set to time. So I run this code and actually is three because there are two in hello and one in world. So I was wrong. And here uh another string method that you can use is the replace method. So we can replace one letter for another. So here let me copy this and I'm going to paste it here. And instead of writing count I can write replaced. So here the first letter that we're going to see here is the letter that we want to replace. So in this case I'm going to change the L with O. And the second letter is the letter that you want to put in that string. So I'm going to use the U. So I'm going to change every time that an O appears here in the string. We're going to replace it for a U vowel. So let's try. So I run this code and now it says well hello world but with U. And these are some of the most common string methods in Python. Okay. Now it's time to learn something that you're going to see often in Python which are variables. Variables help us store data values. In Python we often work with data. So variables are useful to manage this data properly. A variable contains a value which is the information associated with a variable. To assign a value to a variable, we use the equal sign. So let's create a message that says I'm learning Python and store it in a variable called message_1. So here I write message_1 and we set it to the string I'm learning Python. So I open uh double quotes and here I write I'm learning Python. So this is string. We've seen this before. And this is the variable. And we assign this value to the variable using the equal sign. Now I'm going to run this. And as you can see, nothing happens. But actually, we just assigned that string to the variable message_1. Now, if we want to obtain the message, I'm learning Python, we only have to type the variable name and then execute that code. So, I'm going to copy and paste it here. And then we run this code. And as you can see, by running this cell, we obtain the content inside the variable message_1. We can create as many variables as we want. Just make sure to assign different names to new variables. So let's create a new message that says and it's fine and store it in a variable called message_2. So first I write message. So message and underscore 2. And then we set this equal to uh open double quotes and write and it's fun. This is my second variable. And I'm going to run this cell. So as we can see the string was assigned to this second variable. And if I copy and paste this variable here and run this code, we can see that the message it's there. By the way, if you're using single quotes instead of double quotes as I'm using in this video, probably you had the following uh issue. So here I'm going to copy this one and paste it here so you can see what I'm talking about. So let's say you're let's say you're using single quotes instead of double quotes. So you get this. This is a problem that you will have when using single quotes because in the English language we use these apostrophes often. So an simple way to deal with this is using double quotes. So as you can see here if I use double quotes everything is okay. Everything remains as a a string but with single quotes uh it doesn't happen. So only the I gets this string but the rest it doesn't get a string value or the string data type. So just make sure you use double quotes every time you have these apostrophes and that's it. Okay. Now let's put these two messages together. So message one with message two I want to put them together. So this is called a string concatenation. If we want to put message one and message two together, we can use the plus operator. And we can just do this. So I'm going to copy message one or the variable message one. And now I'm going to copy the variable message_2. And I use the plus in the middle to concatenate this first message with this second message. So I run and let's see what happens. So here we can see that the two messages were uh concatenated but here there isn't a space between these two messages. So this is the first message and this is the second and there isn't uh any blank space in the middle. So what we can do here is to just uh add a blank space. So I'm going to copy this one and paste it here. and show you how to do it. So here I add a new plus operator and in the middle we open a string. So with single quotes or double quotes in this case I'm going to use single quotes here and to create this blank space I'm going to press space and here we have our blank space here and then we run this code and now let's see and here as we can see there is a space so between python and the and we have this blank space and if we want we can assign this new message to a new variable. So I'm going to assign this to a variable called message and I write message here and I include here below the code and here I can print this. So as you can see if I run this we can see that the message is there. Okay. Now let me show you an alternative way to join two strings. So this is called the f string and it works like this. You write f and you open a string. So we write a single quotes here. So one and two and here as you can see the whole uh the whole thing is red. So it's like everything is a string. In here inside we can write the message. So let's see uh let's say we write I don't know a simple hello world. So hello world and we run this and as you can see here this is a string. It just has this f uh in front of that string and here uh one of the advantages that this f string has is that it can have variables inside the string. So here for example we can write a variable opening this curly braces. So this curly braces can have variables inside it. So here I can write message uh_1 and we can print it. So if we print we have this string I'm learning python. And now if we want to concatenate this first message with our second message, we just have to include curly braces again. I put it here. And now I write message two. And between message one and message two, I just have to press a space. And we have this. So I'm learning Python and it's fun. So here we just press space and the space also appears here. So for example if we add some random text let's say ABC we get this ABC between Python in between and so this is how F string works. You just have to write the f then open single quotes and inside you can write any message and to include any variable just you have to open this curly braces write the variable name and that's how you join strings. Okay, now it's time to see a data type that is used often in data analysis. I'm talking about lists in Python. Lists are used to store multiple items in a single variable. Lists are order and mutable containers. In Python, we call mutable to objects that can change their values. That is elements within a list can change their values. To create a list, we have to introduce the element inside square brackets separated by commas. So, let's create our first list. First we have to set the name of the list. In this case I'm going to name it countries. And now to create the list we have to open square brackets as I said before. So here we open square brackets. And here we have to write the elements. So I'm going to include in this countries list just strings and they're going to be uh names of countries. So the first one I'm going to write uh United States. So this is the first element in my list and to write the second we have to use the comma. So here comma and now the second. So let's write India uh two more. So now China and finally Brazil. So these are the four countries as you can see here. uh this is a list. So we have the square brackets that represent the list and we have four strings and this is how you define or how you create a list. So now I'm going to run this one and to see the content I'm going to paste the name of this list and now I run here I include only strings but keep in mind that lists can have elements of different types. So for example, one string and the other an integer and then a float and so on. And also lists can have duplicated elements. So for example, I can have here uh United States uh written twice. So here for example, I can write United States twice. And that's okay because lists can have duplicated elements. But I don't want it that way. So I'm going to delete it. and leave it as it is. Okay. Now, if we want to get an element inside this list, we have to use something called indexing. By indexing, we can obtain an element by its position. So, each item in a list has an index, which is the position in the list. Python uses zerobased indexing that is the first element. So, United States has an index zero. The second, so India has an index one and so on. To access an element by its index, we need to use the square brackets again. So, let's see some examples. Let's start by getting the first element. So, United States. So, what we have to do is to write the name of the list, in this case, countries, and then open square brackets. And inside square brackets we have to write the position of this element. So it starts with zero. So we write zero to get the first element and then we run this code and as you can see we got the first element. So if we write here country square brackets one we get India and if we write countries square brackets two we get China. And if we do this with the number three, we get Brazil. So to verify this, I'm going to print each of them. So let's see what happens. So here, print and finally print this one. And now I'm going to run and we should get uh each element of the list from United States to Brazil. So let's try out. So here we have each of them United States the first one then India then China and then Brazil. So it's correct. So this is the most common way to use indexing but there is also negative index. This help us get elements starting on the last position of the list. So instead of using indexes from zero and above we use indexes from minus one and below. So let's get the last element of the list but now using a negative index. So we want to get uh the last element which is Brazil and we did it before with uh countries square brackets three but now we're going to do it with negative indexing. So here I'm going to write countries. I copy and paste it here. And now I open square brackets. And instead of writing three, we're going to write minus one. And this minus one represents the first element starting from the last position. So Brazil will be minus one, China is minus2, India minus3, United States minus4. And that's how it works. So I'm going to run this one. Country square brackets minus one. And we should get Brazil. And we got it. So let's do this one more time. And in this case I want to get United States which is minus1 2 3 and four. So it's countries minus4. So we run this and we got United States but now using a negative index. Okay. Now let's see something called slicing. The slicing means accessing parts of a list. A slice is a subset of list elements. A slice notation takes the form of list. So the list name and then a square brackets and the start. Then this colon and stop. This start represents the index of the first element and stop represents the element to stop at without including it in that slice. So let's see some examples. So I'm going to use this countries list again. I just I'm going to copy this one and I'm going to paste it here. So this is the name of my list. And now I open square brackets and we're going to get uh let's say we're going to start at position number zero and then column and let's get from zero to the position number two. So we have to write three because it stops at three without including this element in the position number three. So let's run this one. And as you can see here, we have index zero, index one, and index two. So it didn't include index number three. And now let's say we want just the first element. So we write from zero to one. So it's only zero and one. No, because it doesn't include one and it stops at one. So here I run and we got only United States. So now let's try something different. Let's say we want to get uh elements from index one to the last one. So let's say let me see here we want to get from India to Brazil. So it's one two and three. So we have to write four because it stops at four and we got three. So let's write here one two 4 and we should get yeah India, China and Brazil. So this is one way to do it. But another way to do it is just delete this and leave it as it is and then run the code. And as we can see we got the same result. So every time you want to get from one position to the last one, you can omit the stop element and just leave it without that element. So just as we did here and the same goes for the start. So let's say we want to get from the first position. So index zero to two. So we don't include the start element and we write only colon and two. So we run this and we get United States and then we get India because this is the first and this is the second. So every time we want to get from the first element or until the last element, we can omit the start and stop elements as we did in these two examples. Okay. Now let's see how we can add elements to a list. There are different methods that help us add a new element to a list. So let's have a look. The first one is called append and we're going to use the counters list as an example. So I'm going to write countries just so you can remember. And here it's countries and as you can see it has four elements. And let's say we want to add a new country to this countries list. So what we can do is just write here or paste here countries and now add append or that append and here as you can see is this is a method. So inside parenthesis we can write the new country we want to add to this list. So let's say we want to add the country Canada. So we write Canada and now we run this code. As you can see nothing is printed. But if we print the counters list again we see here a new element. So as you can see here the append method adds a new element at the end of the list. So this is by default at the end. But what happens if you want to add an element in a different position? So here you can use another method which is called the insert method. So let me show you here. I'm going to copy countries and now I'm going to use the insert method. So I write insert then parentheses and this one uh accepts two arguments. The first one is the index. So the position of the element you want to insert. So let's say we want this at the first position. And the second argument that it takes is the new element you want to add. So in this case, let's say we want to add the element Spain. So this is uh another country and it's going to be uh in the first position. So index zero. So let's try I run this one and again nothing happens. Apparently nothing happens. And here if I uh run this countries list again we can see that there is a new element and this element is Spain and it's located in the first position unlike Canada that was placed in the last position. This is one of the difference between the append method and the insert method. So with insert we can specify the position we want to insert this new element but with append the element is added at the last position. Another thing you can do is to join two lists using the plus operator. We use the plus operator to concatenate strings before but you can also join two lists. So let me show you here. I'm going to create a new list just to show you how it works. So my new list is going to be called uh countries_2. So I'm going to include different countries. So in this case it's going to be uh the UK then Germany and let's write Austria. So we have three countries in this new list. And now I'm going to run this one. And if we want to concatenate this uh first list countries with this second list countries too, we can use the plus operator. So here I write plus and then I run this one. And as you can see I got the five elements from the first list and the three elements from the second list. And another cool thing you can do in Python is putting these two lists inside another list which is called nested list. So let's try out. So here I'm going to create a new list and it's going to be called nested list and here I'm going to open square brackets to create a new list and as elements I'm going to write countries which is my my first list and then comma and then countries_2 and this is my second list. So as you can see here this uh elements inside this list the first is a list and the second is list. So we have a lists inside another list which is called a nested list. So I run this one and then I paste nested underscore list and we run and we get here the first list as first element and the second list as second element. You won't see this nested list so often, but you will encounter this a couple of times. So it's good for you to know. So now we're going to see the opposite of adding an element to a list, which is removing an element. So here I just pasted the countries list we had before. And what we're going to do is to remove some of the elements of this list. So there are different methods that help us remove an element from a list. One of them is the remove method. So to remove an element using this we have to first write the name of the list and then use that that sign and then write remove and write parentheses and inside here we have to write the element we want to get rid of. So first it's United States. So I write United States and let's run this one. And as you can see apparently nothing happens. But if we paste countries here we have uh all the elements but United States is not there. So as you can see the first matching value was removed but you can also remove an element by its index. So this is accomplished with the pop method. So I'm going to copy all of this and now I'm going to paste it here. So instead of writing that remove I'm going to write that pop and here I'm not going to uh use the name of the element but it's index. So I write the index in this case. Let's remove the last one. So it's going to be index minus one. And what pop is going to do is to remove the element with index minus one and then returns this element. So this element is Canada. I didn't run this code here. So you can ignore it. So I'm going to comment this one. And our reference is going to be this this list. And to verify we just write countries and then run. And here as you can see there isn't Canada anymore. And that's how you remove an element using the pop method. But there's still another way to remove an item using an specific index and it's the Dell. So I'm going to show you here Dell. It's uh the function Dell function and here we have to write the countries list and then again open square brackets and here write the index. I write here the index and unlike the pop method, we're not going to get the name of the element we're getting rid of, but just deleting the element. So I run this one and here we didn't get anything. And I'm going to print this. So countries and the element at index zero was removed. So Spain because that's the first element. So we deleted or we remove the first element. So we only got India, China, and Brazil. And there you have it. Three different ways to remove an element from a list. Okay. Now let's see how to sort a list. We can easily sort a list using the sort method. Let's create a new list called numbers and then sort it from the smallest to the largest number. So here first I write numbers and then open square brackets. So I'm going to write uh some random numbers. So first uh four then three then 10 then seven one and then two. So this is my list. So I run this code and now to sort it from the smallest to the largest number we write numbers then sort then open parenthesis and by default this is going to be sorted from the smallest to the largest number. So I run numbers again and here it starts with one and it ends with 10. And as you can see, it's from the smallest to the largest number. So that's the default behavior of the sort method. But we can control how this works. So we can add the reverse argument to the sort method to control the

Original Description

Get started with data science using Python! This course covers essential tools like Pandas and NumPy, plus data visualization, cleaning, and machine learning techniques. Perfect for beginners, you'll gain the skills to analyze and interpret data effectively. YouTube Channel: https://www.youtube.com/@ThePyCoach Source Code & Datasets: https://github.com/thepycoach/python-for-data-science Python for Data Science Cheat Sheet (Free PDF): https://artificialcorner.com/p/redeem-my-udemy-courses-for-free Course in Spanish: https://youtu.be/Rgag-Clu5L4 ❤️ Try interactive Python courses we love, right in your browser: https://scrimba.com/freeCodeCamp-Python (Made possible by a grant from our friends at Scrimba) ⭐️ Contents ⭐️ ⌨️ (0:00:00) Installation and Setup ⌨️ (0:27:23) Python Basics ⌨️ (1:41:41) Introduction to Pandas and Numpy ⌨️ (3:26:15) Project #1 - Web Scraping with Pandas ⌨️ (4:05:36) Filtering Data ⌨️ (5:34:46) Data Extraction ⌨️ (7:31:57) Reshaping and Pivoting Dataframes ⌨️ (7:50:59) Project #2: Making Data Visualizations ⌨️ (8:56:39) GroupBy and Aggregate Function ⌨️ (10:07:41) Merging and Concatenating Dataframes ⌨️ (11:49:12) Regular Expressions ⌨️ (12:45:45) Project #3: Data Cleaning with Pandas ⌨️ (14:17:45) Machine Learning with Python ⌨️ (14:43:45) Project #4: Text Classification with scikit-learn 🎉 Thanks to our Champion and Sponsor supporters: 👾 Drake Milly 👾 Ulises Moralez 👾 Goddard Tan 👾 David MG 👾 Matthew Springman 👾 Claudio 👾 Oscar R. 👾 jedi-or-sith 👾 Nattira Maneerat 👾 Justin Hual -- Learn to code for free and get a developer job: https://www.freecodecamp.org Read hundreds of articles on programming: https://freecodecamp.org/news
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from freeCodeCamp.org · freeCodeCamp.org · 0 of 60

← Previous Next →
1 React: Production Server Setup Part 2 - Live Coding with Jesse
React: Production Server Setup Part 2 - Live Coding with Jesse
freeCodeCamp.org
2 cookies vs localStorage vs sessionStorage - Beau teaches JavaScript
cookies vs localStorage vs sessionStorage - Beau teaches JavaScript
freeCodeCamp.org
3 Browser history tutorial - Beau teaches JavaScript
Browser history tutorial - Beau teaches JavaScript
freeCodeCamp.org
4 Graph Data Structure Intro (inc. adjacency list, adjacency matrix, incidence matrix)
Graph Data Structure Intro (inc. adjacency list, adjacency matrix, incidence matrix)
freeCodeCamp.org
5 React: Parameterized Routing with Next.js - Live Coding with Jesse
React: Parameterized Routing with Next.js - Live Coding with Jesse
freeCodeCamp.org
6 React: Dealing with jQuery Issues - Live Coding with Jesse
React: Dealing with jQuery Issues - Live Coding with Jesse
freeCodeCamp.org
7 setInterval and setTimeout: timing events - Beau teaches JavaScript
setInterval and setTimeout: timing events - Beau teaches JavaScript
freeCodeCamp.org
8 Browser and Device Testing - Live Coding with Jesse
Browser and Device Testing - Live Coding with Jesse
freeCodeCamp.org
9 Last Minute Updates - Live Coding with Jesse
Last Minute Updates - Live Coding with Jesse
freeCodeCamp.org
10 Post Launch Updates - Live Coding with Jesse
Post Launch Updates - Live Coding with Jesse
freeCodeCamp.org
11 React: Setting Up Google Analytics - Live Coding with Jesse
React: Setting Up Google Analytics - Live Coding with Jesse
freeCodeCamp.org
12 React: Masonry Layout - Live Coding with Jesse
React: Masonry Layout - Live Coding with Jesse
freeCodeCamp.org
13 Load Balancing Digital Ocean Droplets - Live Coding with Jesse
Load Balancing Digital Ocean Droplets - Live Coding with Jesse
freeCodeCamp.org
14 try, catch, finally, throw - error handling in JavaScript
try, catch, finally, throw - error handling in JavaScript
freeCodeCamp.org
15 Load Balancing: SSL Passthrough Setup - Live Coding with Jesse
Load Balancing: SSL Passthrough Setup - Live Coding with Jesse
freeCodeCamp.org
16 Graphs: breadth-first search - Beau teaches JavaScript
Graphs: breadth-first search - Beau teaches JavaScript
freeCodeCamp.org
17 React: Masonry Layout Part 2 - Live Coding with Jesse
React: Masonry Layout Part 2 - Live Coding with Jesse
freeCodeCamp.org
18 React: WordPress API Live Search - Live Coding with Jesse
React: WordPress API Live Search - Live Coding with Jesse
freeCodeCamp.org
19 Creating WordPress Custom Post Types - Live Coding With Jesse
Creating WordPress Custom Post Types - Live Coding With Jesse
freeCodeCamp.org
20 Dates - Beau teaches JavaScript
Dates - Beau teaches JavaScript
freeCodeCamp.org
21 Miscellaneous Front End Updates - Live Coding with Jesse
Miscellaneous Front End Updates - Live Coding with Jesse
freeCodeCamp.org
22 Merging a Pull Request from GitHub - Live Coding with Jesse
Merging a Pull Request from GitHub - Live Coding with Jesse
freeCodeCamp.org
23 React + Prettier + Standard JS - Live Coding with Jesse
React + Prettier + Standard JS - Live Coding with Jesse
freeCodeCamp.org
24 React: Sortable Responsive Table - Live Coding with Jesse
React: Sortable Responsive Table - Live Coding with Jesse
freeCodeCamp.org
25 Geolocation Sorting by Distance - Live Coding with Jesse
Geolocation Sorting by Distance - Live Coding with Jesse
freeCodeCamp.org
26 Tradeoff Matrix - Agile Software Development
Tradeoff Matrix - Agile Software Development
freeCodeCamp.org
27 The Definition of Ready - Agile Software Development
The Definition of Ready - Agile Software Development
freeCodeCamp.org
28 Getting first React job without experience - Ask Preethi
Getting first React job without experience - Ask Preethi
freeCodeCamp.org
29 React: Google Analytics Click Tracking - Live Coding with Jesse
React: Google Analytics Click Tracking - Live Coding with Jesse
freeCodeCamp.org
30 Submitting a PR to an Open Source Project - Live Coding with Jesse
Submitting a PR to an Open Source Project - Live Coding with Jesse
freeCodeCamp.org
31 Should I go back to school to get CS degree? - Ask Preethi
Should I go back to school to get CS degree? - Ask Preethi
freeCodeCamp.org
32 Hero Section CSS Changes - Live Coding with Jesse
Hero Section CSS Changes - Live Coding with Jesse
freeCodeCamp.org
33 Working Agreement - Agile Software Development
Working Agreement - Agile Software Development
freeCodeCamp.org
34 A day at Pennybox with Co-Founder Reji Eapen
A day at Pennybox with Co-Founder Reji Eapen
freeCodeCamp.org
35 React: Sorting and Filtering Data - Live Coding with Jesse
React: Sorting and Filtering Data - Live Coding with Jesse
freeCodeCamp.org
36 React: Sorting and Filtering Data Part 2 - Live Coding with Jesse
React: Sorting and Filtering Data Part 2 - Live Coding with Jesse
freeCodeCamp.org
37 React: Building a New UI - Live Coding with Jesse
React: Building a New UI - Live Coding with Jesse
freeCodeCamp.org
38 Definition of Done - Agile Software Development
Definition of Done - Agile Software Development
freeCodeCamp.org
39 Getting started with jQuery (tutorial) - Beau teaches JavaScript
Getting started with jQuery (tutorial) - Beau teaches JavaScript
freeCodeCamp.org
40 Making a React Blog with WordPress Content - Live Coding with Jesse
Making a React Blog with WordPress Content - Live Coding with Jesse
freeCodeCamp.org
41 React, NextJS, CSS - Live Coding with Jesse
React, NextJS, CSS - Live Coding with Jesse
freeCodeCamp.org
42 jQuery events - Beau teaches JavaScript
jQuery events - Beau teaches JavaScript
freeCodeCamp.org
43 React/NextJS Routing and WordPress API Custom Types - Live Coding with Jesse
React/NextJS Routing and WordPress API Custom Types - Live Coding with Jesse
freeCodeCamp.org
44 React: Working with API Data - Live Coding with Jesse
React: Working with API Data - Live Coding with Jesse
freeCodeCamp.org
45 React: Refactoring Components - Live Streaming with Jesse
React: Refactoring Components - Live Streaming with Jesse
freeCodeCamp.org
46 jQuery effects - Beau teaches JavaScript
jQuery effects - Beau teaches JavaScript
freeCodeCamp.org
47 More React Refactoring - Live Coding with Jesse
More React Refactoring - Live Coding with Jesse
freeCodeCamp.org
48 animate in jQuery - Beau teaches JavaScript
animate in jQuery - Beau teaches JavaScript
freeCodeCamp.org
49 "Finishing" My React Site - Live Coding with Jesse
"Finishing" My React Site - Live Coding with Jesse
freeCodeCamp.org
50 Starting a New React Project (P2D1) - Live Coding with Jesse
Starting a New React Project (P2D1) - Live Coding with Jesse
freeCodeCamp.org
51 React Project 2 Day 2: Learning Material UI - Live Coding with Jesse
React Project 2 Day 2: Learning Material UI - Live Coding with Jesse
freeCodeCamp.org
52 The Agile Manifesto - Agile Software Development
The Agile Manifesto - Agile Software Development
freeCodeCamp.org
53 jQuery: get and set with http, text, val, and attr - Beau teaches JavaScript
jQuery: get and set with http, text, val, and attr - Beau teaches JavaScript
freeCodeCamp.org
54 React Project 2 Day 3 - Live Coding with Jesse
React Project 2 Day 3 - Live Coding with Jesse
freeCodeCamp.org
55 The INVEST approach to product backlog items
The INVEST approach to product backlog items
freeCodeCamp.org
56 React Project 2 Day 4 - Live Coding with Jesse
React Project 2 Day 4 - Live Coding with Jesse
freeCodeCamp.org
57 Chickens and Pigs - Agile Software Development
Chickens and Pigs - Agile Software Development
freeCodeCamp.org
58 React Project 2 Day 5 - Live Coding with Jesse
React Project 2 Day 5 - Live Coding with Jesse
freeCodeCamp.org
59 jQuery: add and remove DOM elements - Beau teaches JavaScript
jQuery: add and remove DOM elements - Beau teaches JavaScript
freeCodeCamp.org
60 React Project 2 Day 6 - Live Coding with Jesse
React Project 2 Day 6 - Live Coding with Jesse
freeCodeCamp.org

This video teaches the basics of Python for data science, covering essential tools and techniques for data analysis, visualization, and machine learning. By the end of the video, viewers will be able to analyze and visualize data using Python.

Key Takeaways
  1. Download and install Anaconda
  2. Open and use Jupyter Notebook
  3. Write and run Python code in Jupyter Notebook
  4. Use Pandas and NumPy for data manipulation and analysis
  5. Visualize data using Python
💡 Python is a powerful language for data science, and Jupyter Notebook is an ideal environment for data analysis and visualization.

Related Reads

📰
The Meta-Architecture of Interface Fracture: High-Dimensional Logical Stress and Systemic Collapse…
Learn about the meta-architecture of interface fracture and its relation to high-dimensional logical stress and systemic collapse in complex systems
Medium · Data Science
📰
I Open-Sourced the SEC 8-K Classifier Powering My Forensic Tool — Here's the Taxonomy
Learn how to classify SEC 8-K filings using a open-sourced Python classifier and understand its taxonomy
Dev.to · Jared Ablon
📰
Stop Optimizing Your Data Platform for Dashboards
Learn to shift focus from dashboard-centric data platforms to more comprehensive and flexible systems, and why this matters for business growth
Dev.to · ArisynData
📰
Balancing Card Fraud Monitoring: Strategies to Optimize Risk Reduction and Operational Efficiency
Learn strategies to balance card fraud monitoring for optimal risk reduction and operational efficiency
Dev.to · Ksenia Rudneva
Up next
How AI, MCP & Tableau Extensions Are Transforming Analytics
Salesforce Product Center
Watch →