Data Analysis with Python for Excel Users - Full Course
Skills:
ML Maths Basics90%
Key Takeaways
This video course teaches data analysis with Python, focusing on Pandas and Jupyter Notebook, covering topics such as data types, functions, string methods, list manipulation, and data structures, with a emphasis on practical applications and hands-on exercises using Python 3, Pandas, and Jupyter Notebook.
Full Transcript
if you already work with data in excel and want to add more power to your data analysis and evaluation using python then this is the course for you frank is a data scientist and he will teach you how to use python to work with data hi everyone my name is frank andrade and this is my python course for excel users i created this course to help excel users move from excel to python but why python well in python we can do most of the things we will do in excel such as working with data making charts and pivot tables but that's not all we can use all the power of python to automate tasks work with large data and do a lot of things thanks to the thousands of free libraries python has on top of that python can help you become a better data analyst or get into new fields like data science i divided this python course for excel users in three modules in module one i'll teach you all the python core concepts you need to know for that analysis then in module two we'll learn pandas pandas is a python data analysis library that will help us do most of the things we can do on excel in module 3 we'll put into practice what we learned in this course by creating a pivot table and visualizations such as line plots bar plots and pie charts remember that in the description you will find the files code as well as a free pdf python cheat sheet i created for this course there you will find the concepts methods and functions we will see in this course by the way i'm frank and i will be your instructor in this course so let's get started to download anaconda we go to anaconda.com and click on get started then we choose the last option download anacond installers and then we have here the different anaconda installers so there are windows mac and linux so in my case i'm gonna choose mac and i'm gonna choose that 64-bit graphical installer so now i'm downloading anaconda and once it's downloaded i'm gonna click on it and a message will pop up you just have to click on allow as i'm gonna 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 gonna speed up the video now okay the installation is almost done and now it's telling me that anaconda 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 gonna close this window and i'm gonna open anaconda so i'm going to locate the icon it's a green icon this one that you see here and i'm gonna open anaconda i'm gonna wait a couple of seconds and let's see what was installed so here we have the jupiter lab and jupiter notebook which are widely used in data science so i'm going to launch jupiter notebook so here it's opening jupiter notebook let's give it a second and now we open a new notebook with python 3 so python 3 was installed too and that's it in the following videos we'll learn how to use jupyter notebook in this video i will introduce you to the jupiter notebook interface jupiter 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 a 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 jupiter 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 now we wait a couple of seconds and now we have here the interface of jupyter notebook so i'm gonna 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 anacond scripts so i click here and now i can navigate through the folders and the folder i'm gonna use for this example is this one that says my course and here we're gonna 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 python3 there are other options like text file folder or the terminal but we are not going to use these options in this course so click on python 3 and now we have a python script powered by jupyter notebook so here on the right you can see that it says python3 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 jupiter notebook file we can change the name of the file by clicking here on untitled 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 renamed 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 and here we can create a new notebook with python3 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 jupiter notebook for example after writing many lines of code you can save all the progress you make by pressing ctrl 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 one 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 jupiter 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 sales we can copy sales page sales above and delete sales 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 option so here i'm gonna 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 gonna 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 will help that i think it will send you to that 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 in 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 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 ipy and b 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 is 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 great 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 gonna 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 gonna see some cell types and cell modes in jupiter notebook so first we're gonna 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 for 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 gonna see that the color is gonna 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 one two three so if i write one two three and then i click on this run button i'm gonna 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 introduce so for example i can write 4 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 in the edit mode now we'll see the cell types in jupiter notebook in jupiter notebook there are three main cell types and we can see all of them in this drop down 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 and b convert so we're gonna 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 ctrl 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 drop down 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 one number because i just modified 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 gonna insert a new cell with this button this plus button and now i'm gonna 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 drop down 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 the 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 world with the 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 gonna write double hash sign so i press hash sign twice now space and now i'm gonna 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 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 you 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 and b 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 we convert now we can see that this looks like a plain cell and well this type of cell is not used that often actually we're going to use only that code cell and a 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 gonna see some common shortcuts used in jupyter notebook and we're gonna 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 during 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 gonna 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 and 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 now 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 size the smaller the text so here i'm going to delete these 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 gonna revert to heading one so i press 1 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 plus v we get the cell pasted above so i press shift and v and we get this new cell above this cell i have here okay now i can delete cells by pressing d twice so i press d two times and as you can see here the title disappear 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 juice for shortcut is that control 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 control 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 jupiter 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 gonna write here print and then i'm gonna open parentheses 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 ctrl 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 that 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 jupiter 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 with 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 gonna run this code so just control 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 parentheses and we open quotes because we need to define a string i'm gonna 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 gonna 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 gonna 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 save 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 okay now let's see some data types in python every value in python is an object an object has different data types let's see the most common data types in python so one of the most common data types in python are integer and floats both are numbers but integers are numbers that can be written without a fractional component just like for example the number 1 number 2 three four five and so on so all of them are integers and we can check this value or this data type by using the type function so this is our second function we're going to see so we write type then parenthesis and we execute we run this code and as you can see here in the output it says i n t which represents integer so this is an integer okay the second type of data i want to show you is float floats are numbers that contain floating decimal points so basically uh 2.3 let's say 1.2 fine 5.4 and so on so here we have another type of data and let's check out if these are actually floats so we use type and then parentheses and we run this code and we see that we have float and just like on excel you can perform math operations in python using these numbers so some operations you can use are addition for example you can say one plus two and then execute this code and you get three you can use uh subtraction so four minus one execute and you run this code and you get three you can also do multiplication division exponent and more in python but now let's see the third data type that we will see often on python and it's the boolean boolean are true or false values and we can check this using again the type function and we write type and within parentheses we write for example true and we run this code and we see that we got that bool which represents a boolean data type so we can also write type and in this case false and run this code and we get bull again so this is boolean and we're gonna use boolean often when we use conditionals okay now the fourth data type i want to show you and it's very common is the string a string represents a series of characters and in python anything inside quotes either single quotes or double quotes is a string so let's see them actually we already see one kind of string here when we printed this hello world and you're actually familiar with this but we're gonna see it again so to create a string we have to open either single or double quotes so in this case i'm gonna use double quotes so you see it now and now i'm gonna write any message so i'm gonna write for example again uh hello world and again to verify the type we can use the type function parenthesis run this code and we get 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 a text so here i'm gonna write again hello world but now i'm gonna use some string methods so i write hello world in this case i'm gonna 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 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 gonna 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 tidal case so i'm gonna just copy and paste this twice and here i'm gonna write instead of upper i'm gonna use flower and then title so you can see how it's gonna change the case so here i'm gonna 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 that we don't need it because it's gonna print the last line but just for the sake of this video i'm gonna print the three of them so here i'm gonna run this code and as you can see here the first it has an upper case 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 gonna delete this and actually this one too and we're gonna 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 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 string method is going to do it's going gonna count how many times this l letter is included in this string so as we can see there are two else so it should set two times 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 gonna 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 gonna use the u so i'm gonna change every time that an o appears here in the string we're gonna replace it for a u vowel so let's try so i run this code and now it says well hello world but with you and these are some of the most common string methods in python okay now it's time to learn something that you're gonna 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 that equal sign so let's create a message that says i'm learning python and store it in a variable called message underscore one so here i write message underscore one and we set it to the string i'm learning python so i open double quotes in here i write um 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 underscore one 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 gonna 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 underscore one 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 underscore 2. so first i write message so message and underscore two 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 gonna 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 have the following uh issue so here i'm gonna copy this one and paste it here so you can see what i'm talking about so let's see your 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 and 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 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 this apostrophes and that's it okay now let's put these two messages together so message one with message two i wanna put them together so this is called a string concatenation if we want to put message 1 and message 2 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 gonna copy the variable message underscore two 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 any blank space in the middle so what we can do here is to just uh add a blank space so i'm gonna 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 a 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 and we have this blank space and if we want we can assign this new message to a new variable so i'm gonna 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 uh 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 these curly braces so these correlations can have variables inside it so here i can write message underscore one 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 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 these 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 gonna include in these countries list just strings and they're going to be names of countries so the first one i'm going to write 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 to 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 united states 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 gonna 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 zero base indexing that is the first element so united states has an index 0 the second so india has an index 1 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 in 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 countries square brackets 1 we get india and if we write countries square brackets 2 we get china and if we do this with the number three we get brazil so to verify this i'm gonna print each of them so let's see what happens so here print and finally print this one and now i'm gonna 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 0 and above we use indexes from -1 and below so let's get the last element of the list but now using a negative index so we want to get the last element which is brazil and we did it before with countries square brackets three but now we're gonna do it with negative indexing so here i'm gonna write countries i copy and paste it here and now i open square brackets and instead of writing three we're gonna write minus one and this minus one represents the first element starting from the last position so brazil will be minus one china is minus two india minus three united states minus four and that's how it works so i'm gonna run this one countries 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 wanna get united states which is minus one two three and four so it's countries minus four so we run this and we got united states but now using a negative index okay now let's see something called a slicing slicing means accessing parts of lists as lies is a subset of list elements a slice notation takes the form of list so the list name and then 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 gonna use this countries list again i just i'm gonna copy this one and i'm gonna paste it here so this is the name of my list and now i open square brackets and we're gonna get uh let's say we're gonna 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 3. so let's run this one and as you can see here we have index 0 index 1 and index 2. so it didn't include index number three 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 four 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 0 to 2. so we don't include the start element and we write only colon and 2. 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 that 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 gonna use the counters list as an example so i'm gonna 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 country's list so what we can do is just right 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 parentheses 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 it 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 gonna copy countries and now i'm gonna use the insert method so i write that insert then parenthesis and this one 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 elements pane so this is uh another country and it's gonna be 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 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 task operator to concatenate strings before but you can also join two lists so let me show you here i'm gonna create a new list just to show you how it works so my new list is gonna be called uh countries underscore two so i'm gonna include different countries so in this case it's gonna be the uk then germany and let's write austria so we have three countries in this new list and now i'm gonna run this one and if we want to concatenate these uh first list countries with this second list countries two 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 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 gonna create a new list and it's gonna be called nested underscore list and here i'm gonna open square brackets to create a new list and as elements i'm gonna write countries which is my my first list and then comma and then countries underscore two and this is my second list so as you can see here these elements inside this list the first is a list and the second is list so we have a list 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 gonna 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 in 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 gonna 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 gonna be index minus one and what pop is gonna 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 gonna 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 that index so 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 gonna print this so countries and that element at index 0 was removed so spain because that's the first element so we delete it 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 some random numbers so first 4 then 3 then 10 then 7 1 and then 2. 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 an
Original Description
Learn how to use Python and Pandas for data analysis. This course will be especially helpful if you have experience with Excel, but that is not required. Learn how to create pivot tables, work with data, and make visualizations using Python, Pandas, and Jupyter Notebook.
💻 Source Code & Datasets: https://github.com/ifrankandrade/python-course-for-excel-users
🔗 Datasets: https://drive.google.com/drive/folders/12hFh6RPlX5bWzSqpoMvAeT94RCjCvHw5?usp=sharing
✏️ Course developed by Frank Andrade.
🔗 YouTube Channel: https://www.youtube.com/c/FrankAndrade5
🔗 PDF Python Cheat Sheet for this Course: https://artificialcorner.com/p/redeem-my-udemy-courses-for-free
🔗 My Complete Python Courses for Data Analysis & Data Science: https://www.udemy.com/user/frank-andrade-13/
❤️ 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)
⭐️ Course Contents ⭐️
⌨️ (0:00:00) Intro
⌨️ (0:01:48) Install Python and Jupyter Notebook with Anaconda
⌨️ (0:03:53) Jupyter Notebook Interface
⌨️ (0:13:56) Cell Types and Cell Mode
⌨️ (0:21:34) Jupyter Notebook Shortcuts
⌨️ (0:26:39) Module 1 - Hello World
⌨️ (0:30:30) Data Type
⌨️ (0:39:10) Variables
⌨️ (0:46:53) Lists
⌨️ (1:11:14) Dictionaries
⌨️ (1:21:50) IF Statement
⌨️ (1:28:04) FOR Loop
⌨️ (1:33:49) Functions
⌨️ (1:40:59) Modules
⌨️ (1:44:41) Module 2 -Introduction to Pandas
⌨️ (1:51:08) How to create a dataframe
⌨️ (2:07:34) How to show a dataframe
⌨️ (2:14:24) Basic Attributes, Functions and Methods
⌨️ (2:26:17) Selecting One Column from a Dataframe
⌨️ (2:32:13) Selecting Two or More Columns from a Dataframe
⌨️ (2:37:50) Add New Column to a Dataframe (Simple Assignment)
⌨️ (2:47:51) Operations in dataframes
⌨️ (2:56:04) The value_counts() method
⌨️ (3:00:16) Sort a DataFrame with the sort_values() method
⌨️ (3:09:56) Module 3: Introduction to Pivot Tables in Pandas
⌨️ (3:14:42) The pivot() method
⌨️ (3:20:49) The pivot_table() method
⌨️
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
React: Production Server Setup Part 2 - Live Coding with Jesse
freeCodeCamp.org
cookies vs localStorage vs sessionStorage - Beau teaches JavaScript
freeCodeCamp.org
Browser history tutorial - Beau teaches JavaScript
freeCodeCamp.org
Graph Data Structure Intro (inc. adjacency list, adjacency matrix, incidence matrix)
freeCodeCamp.org
React: Parameterized Routing with Next.js - Live Coding with Jesse
freeCodeCamp.org
React: Dealing with jQuery Issues - Live Coding with Jesse
freeCodeCamp.org
setInterval and setTimeout: timing events - Beau teaches JavaScript
freeCodeCamp.org
Browser and Device Testing - Live Coding with Jesse
freeCodeCamp.org
Last Minute Updates - Live Coding with Jesse
freeCodeCamp.org
Post Launch Updates - Live Coding with Jesse
freeCodeCamp.org
React: Setting Up Google Analytics - Live Coding with Jesse
freeCodeCamp.org
React: Masonry Layout - Live Coding with Jesse
freeCodeCamp.org
Load Balancing Digital Ocean Droplets - Live Coding with Jesse
freeCodeCamp.org
try, catch, finally, throw - error handling in JavaScript
freeCodeCamp.org
Load Balancing: SSL Passthrough Setup - Live Coding with Jesse
freeCodeCamp.org
Graphs: breadth-first search - Beau teaches JavaScript
freeCodeCamp.org
React: Masonry Layout Part 2 - Live Coding with Jesse
freeCodeCamp.org
React: WordPress API Live Search - Live Coding with Jesse
freeCodeCamp.org
Creating WordPress Custom Post Types - Live Coding With Jesse
freeCodeCamp.org
Dates - Beau teaches JavaScript
freeCodeCamp.org
Miscellaneous Front End Updates - Live Coding with Jesse
freeCodeCamp.org
Merging a Pull Request from GitHub - Live Coding with Jesse
freeCodeCamp.org
React + Prettier + Standard JS - Live Coding with Jesse
freeCodeCamp.org
React: Sortable Responsive Table - Live Coding with Jesse
freeCodeCamp.org
Geolocation Sorting by Distance - Live Coding with Jesse
freeCodeCamp.org
Tradeoff Matrix - Agile Software Development
freeCodeCamp.org
The Definition of Ready - Agile Software Development
freeCodeCamp.org
Getting first React job without experience - Ask Preethi
freeCodeCamp.org
React: Google Analytics Click Tracking - Live Coding with Jesse
freeCodeCamp.org
Submitting a PR to an Open Source Project - Live Coding with Jesse
freeCodeCamp.org
Should I go back to school to get CS degree? - Ask Preethi
freeCodeCamp.org
Hero Section CSS Changes - Live Coding with Jesse
freeCodeCamp.org
Working Agreement - Agile Software Development
freeCodeCamp.org
A day at Pennybox with Co-Founder Reji Eapen
freeCodeCamp.org
React: Sorting and Filtering Data - Live Coding with Jesse
freeCodeCamp.org
React: Sorting and Filtering Data Part 2 - Live Coding with Jesse
freeCodeCamp.org
React: Building a New UI - Live Coding with Jesse
freeCodeCamp.org
Definition of Done - Agile Software Development
freeCodeCamp.org
Getting started with jQuery (tutorial) - Beau teaches JavaScript
freeCodeCamp.org
Making a React Blog with WordPress Content - Live Coding with Jesse
freeCodeCamp.org
React, NextJS, CSS - Live Coding with Jesse
freeCodeCamp.org
jQuery events - Beau teaches JavaScript
freeCodeCamp.org
React/NextJS Routing and WordPress API Custom Types - Live Coding with Jesse
freeCodeCamp.org
React: Working with API Data - Live Coding with Jesse
freeCodeCamp.org
React: Refactoring Components - Live Streaming with Jesse
freeCodeCamp.org
jQuery effects - Beau teaches JavaScript
freeCodeCamp.org
More React Refactoring - Live Coding with Jesse
freeCodeCamp.org
animate in jQuery - Beau teaches JavaScript
freeCodeCamp.org
"Finishing" My React Site - Live Coding with Jesse
freeCodeCamp.org
Starting a New React Project (P2D1) - Live Coding with Jesse
freeCodeCamp.org
React Project 2 Day 2: Learning Material UI - Live Coding with Jesse
freeCodeCamp.org
The Agile Manifesto - Agile Software Development
freeCodeCamp.org
jQuery: get and set with http, text, val, and attr - Beau teaches JavaScript
freeCodeCamp.org
React Project 2 Day 3 - Live Coding with Jesse
freeCodeCamp.org
The INVEST approach to product backlog items
freeCodeCamp.org
React Project 2 Day 4 - Live Coding with Jesse
freeCodeCamp.org
Chickens and Pigs - Agile Software Development
freeCodeCamp.org
React Project 2 Day 5 - Live Coding with Jesse
freeCodeCamp.org
jQuery: add and remove DOM elements - Beau teaches JavaScript
freeCodeCamp.org
React Project 2 Day 6 - Live Coding with Jesse
freeCodeCamp.org
More on: ML Maths Basics
View skill →Related Reads
📰
📰
📰
📰
Data Science Institute in Tilak Nagar — AI, ML & Python Training
Medium · Data Science
How to Write SQL Queries That Detect Unstable Join Filtering and Inconsistent Results
Medium · Machine Learning
How to Write SQL Queries That Detect Unstable Join Filtering and Inconsistent Results
Medium · Data Science
Fable 5 Hype: Fangirling with Datasets to Build a Lakers Dashboard
Dev.to · L. Cordero
🎓
Tutor Explanation
DeepCamp AI