Python for Data Science - Variables, Lists and Dictionaries

Nicholas Renotte · Beginner ·💻 AI-Assisted Coding ·4y ago

Key Takeaways

This video teaches the basics of Python programming for data science, covering variables, data types, lists, tuples, sets, and dictionaries. It provides a comprehensive introduction to the fundamental concepts and data structures in Python, with a focus on practical applications in data science.

Full Transcript

what is happening guys welcome to part two in the series on python for data science my name is nikola chernot and tonight we'll be going through a bunch of stuff but specifically we're going to be taking it step by step so if you're a beginner this is perfect for you so we'll build up step by step and build up from going from absolute zero python knowledge all the way right up to being able to build up stuff by yourself so what is it that we're going to be going through tonight well specifically we're going to be going through four key things now these four things sort of form the building blocks of what is python right everything that you learn in this particular video is sort of going to establish a really really good baseline for how you go about stepping through this now specifically we're going to be going through how to create a variable and i'll explain what each one of these is how to create different types of data types or how to create different value types how to work with lists something which is so so common and so so useful when doing python or specifically data sciences style stuff and then we're going to take a look at dictionaries as well so i'll show you the difference between each one of those but before we get to that there's one key thing that i really want to teach you and this is something that i wish i'd known when i started out on my journey in terms of programming in general right so i actually started off as a consultant way before i actually got into python so specifically i was writing stuff in like a proprietary language and if i'd known these things that i'm about to teach or this framework that i'm about to teach you it would have made learning any programming language so so much easier now the thing that i want you to remember when you're learning any programming language is fraud now you're probably thinking nick word on earth is crud well it stands for create read update and delete if you learn how to do each of these four things within any programming language it's going to set you up a baseline that makes it a billion times easier to go and learn anything going on from that so learning how to create different types of data or different value types or different types of objects inside of a programming language is going to really really put you in a good set once you've learned how to create it the next three things that you really want to learn how to do are how to read that so ideally how to view what you've just created how to update that so if you've created say for example a string or you've made a or declared a variable and assigned a number to it how do we make an update to that and again if you are not familiar with any of these things i'm going to explain them all in really really deep detail and then the last thing that you want to learn how to do is how do i delete something that i've just created so if i've created an object how do i go and delete that so say for example i create a variable which is my name so the variable will be called my name and i'll set it equal to nick how do i go and read that well i can type out that variable and see that return to the screen if i wanted to update that how do i go and update that variable i might choose to reassign a value to it and say for example i'm done with the variable now and i want to get rid of it how do i actually go and delete that in python learning this framework so credit is going to make your programming journey a ton easier if there's nothing you take from this by all means do take credit away because it's going to serve you a whole heap longer than potentially this course will because it's applicable to virtually any programming or coding framework okay that's enough of that let's actually get into some coding so we've covered the crud framework let's bring this a little closer and what we're going to do now is get into some coding so remember yesterday we were talking about how to create a jupyter notebook so remember we opened up a command prompt or a terminal and this would allow us to open up a command prompt and or this would allow us to open up a jupyter notebook and from there we could start writing some python code so that's exactly what we're going to be doing in this video but i'm actually going to get a lot deeper into the different components of python tonight so let's go ahead and what we're going to do is we're going to create a new jupiter notebook so remember we need to open up a command prompt and then i'm going to go into the folder that i want to create my jupyter notebook so i'm going to put this side by side so you can see it so i want to create it inside of a folder called python basics but you could create this wherever you wanted to create it right so if you wanted to create it on your desktop you could if you wanted to create it in a specific folder that you've got for learning you could definitely do that as well what i like to do is keep all my jupyter notebooks associated to a specific project in the same location so over here what i'm actually going to do is put it inside of a folder called python basic so you can see that up there so i've got a folder inside of my d drive inside of a folder called youtube and then inside of a folder called python basics so that's where we're going to be putting all of our notebooks for our variables different data types lists and dictionaries so we're going to be putting them all in there now first up what we need to do is from our terminal we need to navigate to that folder so i'm just going to navigate to it so in order to do that on my windows machine i can first go to my d drive and then what we need to do is go into the youtube folder so i'm going to go and again if you wanted to do it inside of a different folder you could if you wanted to do it on your desktop you could just go into whichever folder that you want to execute it from i could execute jupyter from this top level folder and i'd be perfectly fine as well so i'm going to go into the folder that i want to create it in so i'm going to go into my youtube folder and go into my python basics folder and then what i'm going to do is i'm going to start jupyter notebooks pop quiz how do we start jupyter notebooks again i've literally given it all 80. so you type in jupyter notebook so that has now gone and opened right so you can see that they opened up on my other screen but that's gone and opened up our jupiter notebook so we can now start to write a little python code now what we need to do is create a jupyter notebook so again what we learned from the first lesson is to create a jupyter notebook all we need to do is go over to the right over here and all we need to do is hit new and we're just going to use our default python environment and hit python3 and that is our notebook now opened up so this is going to be the notebook that we're going to use for pretty much the majority of our python basics components so what we're going to do is we're going to name it item basics so remember to rename it all you need to do is go right up here where it says untitled and we can just step into that and call it uh python basics and hit rename pretty cool right all right so we've gone and done that now remember the last thing that we also learned is that we've got different types of cells when we actually go and use a jupiter notebook so we've got a code cell we've also got a markdown cell we've got this raw notebook convert cell and we've also got a heading cell so what we're actually going to do is we're going to convert this first cell into a markdown cell because we want this to sort of be to allow us to break up our code so we're going to step out of it because remember it's green at the moment so if i hit escape it's going to go blue means it's not active and then i'm going to hit m on my keyboard to convert that into a markdown cell so you can see that that's happened there then what i'm going to do is we're going to add a pound symbol to give us a bit of a header and we're just going to call this initial section variables cool so that is our first header now set up now what we need to do is we are going to first up learn a little bit about variables actually let's give this a number as well i'm a sucker for numbering and structuring if any of you guys have seen any of my videos before so first up what is a variable so i want you to think of a variable as a placeholder which you can repeatedly refer to when you're trying to grab a value so say for example i wanted to have a placeholder that holds my name i could create a variable and then pass it a value and access that variable whenever i need to if i wanted to later on i changed my name i can go and update that variable so that again all i need to do is refer to that placeholder and i can get my current name at that point in time so say for example um this particular component or the these coupler series that we're actually going to go through are going to have a bit of a space theme to it given uh i've been get we're getting really into tesla uh spacex not tesla more i'm into tesla as well but really into spacex so we're going to call it space name so this is how we define our initial variable now as of right now our variable isn't defined so if i go and hit shift enter it's going to give me this error here so it says name error name space underscore name is not defined now in order to define it i actually need to assign a value to this variable so in order to do that all i need to do is assign it all i need to do is add a space type in equals and then give it a value so right now i don't i haven't actually given it a value so i need to give it a value now say for example we wanted to store our name in this so what we can do is add quotes and then my name is going to be astronaut not nick so that is our variable now created pretty cool right and that is variables done no okay so we're going to go in into this in a little bit more detail so that's our variable now assigned now if i go and take a look at this variable now so if i type in space underscore name i can now get that value back so you can see that it's now printing out astronaut nick and remember if we use our print function we can print that out as well and it's gotten rid of our quotes now a key thing to note is that we've gone and defined this variable and we've given it this value right so what does this value actually represent well in the python language it actually represents a specific data type called a string now we can actually check the different types of data that are assigned to variables and the way to do this so remember we've used the print function to print out a variable but what we can also do is use another function called type to check what type of variable a specific variable is so if i type in type over here so typ e and then inside of the brackets if i pass through my variable so space underscore name you can see that it's printed at str now this represents the fact that it is a string there are a bunch of different types of variables or different data types inside of python so say for example rather than having my name as astronomic i wanted to set it as a number again it probably doesn't make sense but let's say for example add a serial number right so say my serial number was one two three four five six uh let's actually type into it typing in the wrong space one two three four five six so what i've actually just gone and done there is i've gone and reassigned a new value to my same variable now if i go and print it out you can see that that value has now gone and changed so remember initially we actually held our name in there and now we've got an assigned rather than having a space name or my actual name in there we've now gone and changed it to a space name id for example and you can see there that it's now one two three four five six remember how i said that what we've actually gone and done here is we've assigned a specific data type to our variable if we go and take a look at this type now you can see that rather than saying str it now says int now int actually represents an integer so this is a number that doesn't have any decimal places if i added 0 1 2 and went and did the same and remember so what i've gone and done is i've gone and reassigned a new value to our variable now and if we go and print this out you can see that it's now returning the word float this is again a different data type now we're going to take a look at all the different data types but let's quickly recap on what we've done there so first up what we've gone through is we've taken a look at variables now remember a variable is sort of like a placeholder or a reference to a specific value or data type that you might want to use inside of python now in your data science journey you're going to be using variables all over the place more often than not you're going to have multiple variables that you're working with you're going to have different things assigned to them this is a really fundamental concept that you really want to make sure that you understand so we're going to define our variable we've gone and printed it out and we've also learned how to take a look at what type or what data type is actually assigned to a specific variable so remember we can print out a variable using the print function and we can also take a look at the type using the type function down here so that is variables in a nutshell now we've talked a bit about different data types right so remember we first up assigned a string so if we go and type in control z so it was initially astronaut nick and then we changed it to one two three four five six and then we went and added a decimal place and added some additional numbers to it so what are we going to do now we're actually going to take a look at all the different types of data types that we've actually got available so inside of our new cell again we're going to get into a repeatable process so we're going to structure our notebook really really nicely so we're going to convert this cell to a markdown cell now how do we do that again we need to step out of it so if i'm inside at the moment and it's green if i hit escape it's going to go blue which means it's not active at the moment and if i hit m on my keyboard it's going to go from a code cell up here to a markdown cell so if i hit m watch this cell up up here let's actually zoom in so you can see it if i hit m boom markdown remember if we want to go back to code it's y m is markdown y is code m is marked down y is code so that's what it gives you a feel for how you can quickly convert these cells so we're going to hit m to keep it as markdown and we are going to define a new section now this next section just so happens to be called data types so we're going to add in a pound symbol again and we are going to define our new section as data types now you're probably thinking nick why are you spending so much time on variables and data types well these are the fundamental concepts that you're going to want to learn when you go and start leveraging python for data science so often i've got stuck on a specific theme because like i haven't had a specific value in a specific type or a specific format so understanding the different types of variables or the different types of data types that you've actually got available inside of python is going to make your life a billion times easier believe me like if there's one piece of advice i can give you it's make sure you understand this it's going to serve you a long while and make sure you understand crud c-r-u-d create read update delete super important okay so that is our variable section and now done now we're up to our data type so we've already gone and taken a look at three different data types so we took a look at our string we took a look at an integer and we took a look at a float so if we go and create a new variable now so we're going to call this one test variable and what we're going to do is we're going to assign it a string so we're going to create a first data type and we're going to call this so remember the way to write a comment inside of python i can't remember if i covered this in the last thing but we can actually add additional comments inside of our code cells using the pound symbol again so sort of similar to what we're doing up here so right down there so you can see i've added a pound and if i actually type in a comment here this is declaring a variable make sure we can see it variable as a string cool so this here is not actually going to execute so this is what is referred to as a comment inside of our code and it is very good practice to write comments within your code because it's going to help you remember what on earth you've written so often i've gone and written giant blocks of code and then i'm going man specifically the next day i'm going i really wish i'd gone and written some comments because yesterday nick really wasn't thinking or looking out for future nick so adding comments really really good practice okay so we're going to call this test underscore variable and we are going to assign it a string so this is our first data type that we're going to take a look at so string so remember a string is really just a bit of text so when you're working in nlp you'll find that you're working with lots of strings sometimes you'll also have variables or feature columns within your data science projects that are stored as strings as well so again good to know this so we are going to call this test variable and again keeping with a space theme so we're going to say it's pluto so again the planet so that is our variable now assigned now what we can do is we can print that out so if i type print test underscore variable you can see that we've gone and printed out pluto another cool thing to note is that we can actually execute more than one line of code in one cell so if i cut this by pressing control x so again control z control y control x control v or work inside of our jupyter notebook so if i paste that there this is not only going to assign our string data type to our variable it's also going to print it out at the same time so if i go and run this you can see that we've gone and printed it now i'm going to clean this up so i'm going to delete this cell here and remember to delete a cell in our jupyter notebook we hit dd and that deletes it so let's take a look at what we did there so i wrote test underscore variable so this is creating a new variable and then remember we have to assign a value to that variable for it to be valid so i've written equals and then inside of quotes i've written pluto and then i've closed those quotes and then to print out our variable and see what it actually is i've written print and then test underscore variable now remember we can take a look at what our variable type is by typing in type and then passing through our variables so if i pass through test underscore variable you can see that that has now gone and printed out a string let's actually keep this clean so this is going to be our string variable let's make it so what i'm going to do is i'm going to rename my variable well it's not actually renaming we're actually declaring a new variable now so we're going to call it string variable and then paste that in there and then paste that inside of our type as well so that is our first variable now defined or our first data type now taken a look at so we've now gone and declared a string now the next type of data type that we want to take a look at is an integer so remember we did that one up here as well so we are going to create a new variable called integer variable remember you just need to type it out and let's add in a few additional cells again pop quiz how do we add more cells below it's bb and that gives us the ability to add a bunch of cells into our jupiter notebook now what we can do is what were we doing we're assigning an integer variable so we've gone and done our string now we're going to go ahead and do or create our integer variable so again good practice add some comments so this is declaring a variable as an integer an integer is basically a number that has no decimal places so if i type in one two three eight five two and then print it out you can see that we've gone and created that integer there and if i change my print function to type you can see we've gone and created our integer variable so that is integer variables in a nutshell now think of your integer variables as variables that you're going to use pretty much everywhere so whenever you're doing math you're more than likely to use these variables so say for example i wanted to add 10 to this variable so we're going to look at math functions a little bit more later on but say for example i wanted to add some values to this integer variable here well i can do that so if i type in integer variables so remember we can access it like that and if i wanted to add a value to it i can just type in plus 10 and you can see that we have now taken our placeholder variables remember our integer variable and we've gone and added 10 to it so before it was 123 852 and then by typing in plus 10 we've now gone and incremented it so it's now 123 862. so that is integer variables in a nutshell now so so far we've taken a look at string variables and then we've taken a look at integer variables the next data type that we want to take a look at is a float so remember we took a look at a float up here as well now the key difference between an integer and a float is going to be the fact that a float has a decimal place and has trailing values so if i go and do this now so we're going to create a float variable and we are going to set that to one two eight one two eight point one two three or one two six and then if we take a look at our type you can see that we've now gone and declared a float so again let's add some comments so this is declaring a variable as a float and there you go so what we've gone and written is float underscore variable equals 128 dot or point 126 and then so that's basically gone and created a new variable and assigned a float value to it and then what we've also gone and done is we've gone and taken a look at our type so i've written type and then i've passed through our float variable to that function and you can see it's gone and returned float so that is our third data type now there are a bunch of others that we're going to take a look at as well so say for example you wanted to do some conditions and take a look at something whether or not it's true or false so this is going to be particularly important when we actually get to our conditions section of this course so we can actually create a new variable called a binary variable now this is also referred to as a ball so let's actually do name it correctly so ball variable and the reason it's called a ball variable is it stands for boolean variable so either one or zero true or false so let's actually write our commentary so this is declaring a variable as a boolean value well it's actually assigning a boolean value to a variable cool and what we were doing there so we've gone and created our variable now what we need to do is assign it so let's take a look at our different types of boolean variables so i can assign it as true and you can see that as soon as i sign it as true so right down here it's gone to this green value so this represents the fact that we're now working with a reserved word inside of python so true is a reserved word so this just basically means that you can't go and name something this particular thing or it's not good practice too so if i go and take a look at our type and type in bull variable you can see that it's gone and exported the fact that it is a boolean value now there are two key types of boolean values so it can either be true or false and you can see that is also a boolean value now if i type in um lowercase let's actually pass through a string rather than actually passing through the reserved word so if i type in true and remember string is something that's wrapped inside of our quotes so remember we've got these quotes here so no difference where how we went and defined our string variable up here which was pluto so if we went and did this this is not going to return or what do you think it's going to return is it going to return boolean no it's going to return string this is because it is not using the reserved word it's actually passing through a string so in order to get a true true value or boolean value we need to get rid of these quotes and again now it's going to define our boolean value now you're probably wondering where you're going to use a boolean value where really really often when you're processing data and again we'll get to this when we take a look at our pandas components of this course say for example you want to check whether or not a particular set of values is over let's say 50 you might go and say is or you might write an if statement so if x is greater than 50 then return true and basically you're going to have the return value assigned as a boolean value so either true or false now sometimes this is also represented as a one or zero so i'm going to show you a something which i like to take a look at as well so if i type in bool this is known as type casting so i can actually convert a value to a specific data type so you can see that i've written bool here and if i pass through 0 you can see it's still returning boolean as the type and if we take a look at our variable it's actually gone and converted our zero to the reserved word false so this is actually converting a specific value into a different value now again there's a whole bunch of these so the one for string is str and you can see that that's in green down there the one for integers so let's actually add these as well so if we can actually i'll give you a cheat sheet if you want these so there's str which is type casting to a string there's inte or int for integers there's float and again you can see that these are all green there's boolean which we've just taken a look at and there's a bunch of others so again this allows us to convert a value into a different type of value so if ever you need to convert one value or one value data type into a different type of data using these type casting tools make it a lot easier to do that as well cool so that is our boolean value now defined now what's our next one that we're going to take a look at so the next one is probably the one that i use the most in data science and this is a data type that you're going to come across a ton and we're going to cover this now at a high level but we're going to take a step and we're actually going to delve into it a whole heap more in a second so what is this illustrious or elusive data type well it's called a list and a list is also known as an array in other programming languages but in python it's called a list now you're probably thinking what on earth is a list well it's a number of values and stored within a specific data type so inside of a list i can actually have integer values i can have float values i can have boolean values but just think of it as like a bit of a shopping list so you can add a whole bunch of stuff to a python list and actually return all of those values so let's actually go and define one so we're going to create a new variable again consistent theme i know it's repetitive but it's going to help it sync in so if we type in list variable and we are going to assign it a list so how do we actually create a list the core defining characteristic when defining a list is that it's inside of square brackets so you can see that there right so i've gone and defined oh we haven't added comments what are we doing let's add a comment so this is creating a list variable so what are we doing so we're creating our list variable down here and right now it's an empty list so say for example we wanted to add in a bunch of stuff to it well we can add in a bunch of numbers so i can type in one two three and take a second to think about this what values and am i putting into this list right now give me some thinking music terrible singing so these are actually integers right so remember they're taking this format up here right but i can also add floats i can add in other values 85.4 22.1 cool so now what i've gone and done is i've gone and created a list if i go and hit shift enter that has now gone and created our list variable and if we add in our type function and press type list variable you can see that we have in fact created our list so what have we actually gone and written there so we've written list underscore variable equals and then the defining characteristic of when you go and define a new list is the fact that you have to put it inside of square brackets and this is really really important because there's other really similar types or data types which use other types of brackets but a completely different data type so again list inside of python uh wrapped inside of square brackets cool so that is our list now created and so we've created square brackets and then we've added in a value and we separate each value by a comma so you can see that there so i've added in a value and this particular value is an integer comma so my next value is 2 comma my next value is 3 comma my next value is 123.44 comma next value 85.4 comma last value 22.1 and then close our square brackets so that is a list variable and if we take a look at it so that is what our return value actually looks like so that's what it looks like when we go and print it out now i'm not going to show you how to crud this because remember we need to so what we've only really done so far is we've taken a look at how we can create and read these values we're going to delve into a little bit more detail once we actually get to our list section and specifically our dictionary section in a second as well so we'll take a look at how to update and delete those so that is our list variable now created so quick recap so we've taken a look at string values and we assigned it pluto so key defining characteristic of a string is it's wrapped inside of quotes we've declared an integer and the key defining characteristic of an integer is that it's made up of numbers with no decimal places and no trailing values we've defined a float which is a inter or numeric value with trailing numbers we've defined a boolean which is really true or false and we also took a look at how we can do a bit of typecasting and then we went and created a list and the key defining characteristic of the list is that it is a number of different values wrapped inside of a set of square brackets cool the next data type that we're going to take a look at is a tuple so again a triple is very similar to a list but with one key defining characteristic you can't add in values or the exact same value multiple times so this is the yes so if you kind of add in multiple values time so let's actually go and define a tuple so if i type in um tuple variable and so what we're going to do add some comments hit create a and to be honest i don't use the triple variable that much every now and then and there's a specific library that i've used that actually requires a tuple but more often than not i'm using lists um tuples you'll find are pretty common when you're working inside a computer vision and you need to define coordinate values so x and y and z but more often than not you're probably going to mainly be using them for that use case mainly you're probably mainly going to be using lists the other most common data type that i use outside of the base ones which are integer floats and strings is a dictionary which we'll come to in a second so um what's our comment so create a tuple variable and let's add in some more cells so how do we add in more cells we add bbb to add more cells below cool let's add two balloon caps so if i type in triple underscore variable and set that equal to right so what is the defining characteristic of how we actually go and define a tuple well this is why i said pay a lot of attention to the type of brackets that you use so these are square brackets out here here we're going to use parentheses or curved brackets right so parentheses and then we're going to add in values so i'm going to copy this over and paste this into our tuple so you'll see that it's defined in a very similar manner the only difference is the type of brackets that we use so for a list we use square brackets for a triple we use curve brackets or parentheses and if we go and type in type and triple variable you can see that we've now gone and created a tuple variable so if we go and type in triple variable that is our triple variable now i said there is something which makes a triple variable different to a list so let's actually quickly take a look at how we can get values out of a list so again you'll see that this is similar when we access values from a tuple so say for example i wanted to grab this first value out of my list and this is going to be really common right so you'll put a bunch of stuff in a list and you'll loop through each one of these values so we're going to cover loops later on um so you loop through the values and you'll apply some logic or you'll do a check again you want to be able to access each one of these values so if i type in adding a set of square brackets after my list variable and pass through the value 0 this is going to give me the first value in my list so again this is referred to as indexing so i'm passing through the zeroth index to this list and i'm getting the first value back so remember our values were 1 2 3 123.44 85.4 22.1 if i go and pass through 1 i'm going to get the second value which is 2. if i go and pass through 2 i'm gonna get the third value which is three and if i go and pass through so zero one two three four five if i go and pass through five i'll get 22.1 so if i do that 22.1 now the reason why i sort of jumped at the gun a little bit for this is because it's the same way that you go and go or triples operate in the same manner so if i wanted to get the first value out of my 24 i can do that and you can see i've now gone and grabbed the first value if i go and pass through one i've gone and grabbed the second value gone passed through the index two i'm gonna grab the third value a core difference between tuples and lists is that you can't have multiple values of the same value inside of a tuple so if i go and define this actually is that right no the core defining characteristic of a tuple is the fact that it's immutable so let's take a look at this so immutable just checking my notes there so when we are working with lists and tuples the so i could go and update this value inside of this list up here right so say for example i wanted to change the fifth value or the six value inside of this list to a different number so say for example i wanted and again i'm sort of blanking on these because again i don't use tuples and i don't use um i don't use sets which we'll take a look in a second that much so again you'll probably find that you don't use these types or these data types all that much so if i wanted to go and update a value inside of our list to a different number right so right now it's 22.1 that's our last value if i went and typed in a new number so remember this is a variable assignment so we're now going and passing through a different number and we're going to cover this in more detail in a second so if i go and assign it to 123 and we go and take a look at our list now list variable you can see that we've now gone and changed that number so before we assigned it was 22.1 when we went and did this so i wrote list underscore variable and then inside of square brackets i've passed through the index five and then i've set it equal to 123. so this is updating our list with a new number and you can see that when we go and output it we're going and outputting that new value there core thing with a tuple is that it is immutable so that means you can't change values inside of that tuple once you've defined it so if i were to try to go and do this same thing here to our tuple so if i go and grab index 5 and try to set it to 123 we should get an error and you can see that there so it says triple object does not support item assignment so this basically means that you can't go and update values inside of your tuple once you've gone and declared it up here and that is a core defining characteristic of tuples that they are immutable so remember that immutable cool all right the next thing that we're going to take a look at is the set so actually let's quickly recap on tuples so triple variables are defined so we've defined our triple variable so tuple underscore variable equals and the defining characteristic of a triple is that it's defined using parentheses and the main difference between a list and a tuple is the fact that a tuple is immutable which means you can't change values let's make that in simple terms you can't change the values cool okay now the and then so we also went and checked the data type and remember we went and tried to go and update our tuple and that's going to throw an error because we can't go and update the values because they are immutable so you can go and update the values core thing if you wanted to go and update the values in your tuple what you would need to do is convert it to a list first make your updates and then convert it back to a tuple but this is sort of like recreating it right so again just keep in mind when you've got a tuple you can't go and update the values in that the next type of data or the next data type that we're going to take look at is the set so again this is one that i don't use all that often it is used sometimes and sometimes i use it because it actually has a really unique function and let's actually take a look at this so we're going to create a set so let's add in our comments i'm just going to overwrite what we had in that cell so this is creating a set variable so let's go and do it so we are going to create a new variable called set underscore variable and we're going to set that equal to all right so again this is why i said the types of brackets are really really important i wish i'd known this when i was learning python because i was like why can't i update this value and it's like oh it's using curve brackets rather than square brackets that's why i can't do it a set uses another different type of brackets go figure this actually uses curly braces so again we pass through curly braces and then we can pass through the same values up here and that is our set created now you're probably thinking nick why the hell are you teaching me sets i'm going to tell you in a second so if we go and check take a look at our type set variable cool so you can see there that it is in fact a set all righty and let's just close slack all right so we've now gone and created a set so what was i going to tell you about sets oh okay so the unique property about them so let's take a look at sets and let's try and update a set value so if i go and try to update the fifth value like we did with our list again you can see that sets are also immutable all right so immutable you can't change the values but they also have another property because you're probably thinking now all right nick you've told me about sets you've told me about tuples but like a set right now just looks pretty much the same as a tuple but it's inside a curly bracket so well sets have another property that um you want to take note of as well so sets can't contain values of the same value so they can't contain duplicates basically so say for example we go and add in another value to our set so what i'm actually doing here is i'm not updating the set i'm creating the variable all over so this is why i'm allowed to reassign it up here right so this is not reassigning it's creating it all over again so if i go and pass through a new value so let's go what do we have in there already one two three so let's go and add a three cool all good looks fine right no errors now if we go and take a look at our set you can see that it only has these what is it six values so one two three four five six it doesn't have that trailing three and that is because you can't store duplicates right so if we go and try to do that with our tuple and if we go and output a tuple oh what am i doing tuple variable you can see that we do in fact have that trailing three on there our set is different from our tuple in the fact that again it's still immutable that's a similar characteristic that it's got but a core thing is that it doesn't contain duplicates now this actually comes in handy right so say for example you got a big list of values and you want to strip out all the duplicates having it set as a set can be useful sometimes right so say for example we've got our tuple variable up here so we've gone and defined it as a tuple but we're like well let's let's actually do it with our list so let's go and add in some duplicates so one two three one two three right so right now a list has a ton of duplicates right so it's got one two three one two three dot four four eighty point 85.4 22.1 one two three one two three now say for example and again this is what i actually use sets for in real life so i don't like i'm sort of teaching you why i use these particular data types so why on earth do we use sets so say for example i taught you a little bit about typecasting up here so say for example i wanted to get rid of all these duplicates inside of our list now with numpy you've got other functions and we're going to cover that later but what i can actually do is i can typecast this and actually convert it to a set get rid of the duplicates and then convert it back to a list so what we're going to do is do this so let's add a comment the typecasting list and i think i've actually got some more yeah i've got some more stuff planned on typecasting but i wanted to give you a little bit of background as to why we go and do this so what are we going to do we're going to typecast our list to a set and then back to a list to get rid of duplicates so what we can actually do now is we can actually do this so let's grab our tuples remember our triple variable is up here right so we've got our tuple which is no what are we doing we're doing it on our list because remember our list has got duplicates list and what we want to do is get rid of all these duplicates so what we're going to do is we're going to type cast it to a set and so what i've written there is again you can see that in green there so i've written set and remember it's in green because it's a reserved function and then we've gone and passed it into this function over here so we've gone and passed through our list variable right and so if i go and output this you can see that it converts it into a set which now has curly braces but say for example we wanted to do more stuff with this we want to convert it back to a list so we can actually wrap it in another typecasting function again these aren't actually called typecasting functions but that's what i actually use them for so they're actually used to set variables of this specific type so if we go and go and wrap this inside of a list function over here which you can see that there so we've now gone and taken a list variable we've wrapped it inside of a set and we've wrapped it inside of a list function so if we go and output this that effectively takes this list variable that we had up here and goes and strips out all of the duplicate values and still returns a list so if we take a look at our type now still a list how cool is that so that's what i tend to use sets for most often so again you're probably thinking about all of these data types you're wondering why are we using all of these or why are you teaching me all of these these are the main reasons tuples i probably don't use too much but mainly in computer vision uh sets mainly for removing duplicates more often than not okay so we've gotta covered a bunch of stuff now so we've taken a look at strings and we defined that as pluto's remember strings are wrapped inside of quotes gone and defined an integer variable so the defining characteristic there is it is a number with no trailing decimal places i've gone and defined a float value so 128.126. so remember it's got a decimal point and floating values we've gone and defined a boolean value so true or false with a capital gone and defined a list so the defining characteristic there is having a set of square brackets or wrapping everything inside of a set of square brackets we've then gone and defined a tuple and again the defining characteristic of a tuple is that you're using parentheses or curved brackets and a key difference between a tuple and a list is the fact that a tuple is immutable so you can't go and change the values once it has been declared we've also taken a look at a set and again a key defining characteristic of a set is that it's defined by squiggly brackets or whatever you want to call them and then again they're immutable but they also cannot hold duplicates they'll get rid of the duplicates if you do pass them through we have one last big one that i want to show you so this last type or data type is actually called a dictionary so let's actually go and define a dictionary so we are going to create a new dictionary called dict variable and add in a comment defining a dictionary variable and let's go and do this so let's actually define it first and then i'll explain it to you so i'm going to set it equal to squiggly brackets you're probably thinking nick this is a set no it's not so it's going to be a dictionary and then we're going to define a key i'm going to set this equal to name and then nicholas and then age actually let's type in favorite color let's actually put these in the same type of quotes as well is red uh to do favorite number 20. that is our dictionary variable now defined now you're probably thinking nick what the hell have you gone and showed me so a dictionary variable is made up of two key defining characteristics these are keys and values so let's actually take a look at what we went and wrote oh well let's actually take a look check out type so if i type in type dict underscore variable you can see it is in fact a dictionary we go and print it out again printed out our dictionary but you can see here that this is sort of taking a little bit of a weird shape so we've got these squiggly brackets and then we've got these values followed by a colon followed by a value or another string here this one's got a number you're probably thinking what on earth is this so dictionaries are used really really often inside a data science so again the main debt type of data that i use is a list when working with different data types you're obviously going to be using strings booleans floats and integers really really often the main sort of grouping data type that i tend to use is a list and a dictionary now a dictionary allows you to assign or create keys and assign values to those so say for example i wanted to create an object which represents a person i might actually create something which looks a little bit like this so i might actually rename this person and then let's go and create take a look at our dictionary variable or person variable and you can see there that i've now actually gone and output that out now this dictionary is made up of two key things it's made up of keys and it's made up of keys and values so i've gone and defined name which in this case is a key and then by in order to set a value to a specific key we go and pass through a colon and then we go and pass through a value so this is one key pair that is often what it's referred to so it's got a key and it's got a value and the way that we set it is we pass through the key we set it equal to or we use a colon to actually set that value and then we separate them using a comma so then i've gone and set another key and in this case i've set it equal to favorite underscore color and then in order to set that value i've equaled i've set it equal using a colon and i've set it equal to red then our last key is favorite underscore number and again this is inside of quotes and in order to set our favorite number i've used a colon and i've passed through the value 20. now you're probably thinking all right this is great but how do i actually use this so say for example i wanted to now go in ahead and grab the name of my person inside of my dictionary variable well remember when we use lists we go and pass through the index value right so we go and pass through 0 1 2 3 whatever with dictionaries we go and pass through the key value so in this case say for example i wanted to grab the person's name i can actually pass through the key name and that goes and returns the dictionary keys value if i wanted to return the favorite color i can pass your favorite color and that returns red if i wanted to go and pass your favorite number i can now return the value 20. so again that is the last data type that i really wanted to focus on in this particular case now we're going to build up on all of this but this sort of really establishes a core baseline for the different data types you're likely to encounter when you're going on your data science journey so let's take a look at how we actually define that so written person underscore variable set it equal to curly braces and then we've gone and defined our different key and value pairs and the way to set a value is you use a colon and you separate each key value pair by a comm

Original Description

In this video you'll learn how to get started with creating variables, lists and dictionaries with Python with a focus on using it for Data Science. In this video you'll learn: 1. How to Create Variables in Python 2. Different data types and objects you'll encounter 3. How to work with lists 4. How to work with dictionaires Chapters 0:00 - Introduction 6:48 - Creating Variables 14:52 - Data Types 57:21 - Lists 1:08:20 - Dictionaries Oh, and don't forget to connect with me! LinkedIn: https://bit.ly/324Epgo Facebook: https://bit.ly/3mB1sZD GitHub: https://bit.ly/3mDJllD Patreon: https://bit.ly/2OCn3UW Join the Discussion on Discord: https://bit.ly/3dQiZsV Happy coding! Nick P.s. Let me know how you go and drop a comment if you need a hand!
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Nicholas Renotte · Nicholas Renotte · 0 of 60

← Previous Next →
1 Face Detection - Build An Image Classifier with IBM Watson - Part 7
Face Detection - Build An Image Classifier with IBM Watson - Part 7
Nicholas Renotte
2 Food Image Classification - Build An Image Classifier with IBM Watson - Part 6
Food Image Classification - Build An Image Classifier with IBM Watson - Part 6
Nicholas Renotte
3 General Image Classification - Build An Image Classifier with IBM Watson - Part 5
General Image Classification - Build An Image Classifier with IBM Watson - Part 5
Nicholas Renotte
4 Installing Watson Developer Cloud - Build An Image Classifier with IBM Watson - Part 4
Installing Watson Developer Cloud - Build An Image Classifier with IBM Watson - Part 4
Nicholas Renotte
5 Generating Credentials - Build An Image Classifier with IBM Watson - Part 3
Generating Credentials - Build An Image Classifier with IBM Watson - Part 3
Nicholas Renotte
6 Creating A Service - Build An Image Classifier with IBM Watson - Part 2
Creating A Service - Build An Image Classifier with IBM Watson - Part 2
Nicholas Renotte
7 Getting an IBMid - Build An Image Classifier with IBM Watson - Part 1
Getting an IBMid - Build An Image Classifier with IBM Watson - Part 1
Nicholas Renotte
8 How to Analyse Review Data - Part 2 - Python Yelp Sentiment Analysis
How to Analyse Review Data - Part 2 - Python Yelp Sentiment Analysis
Nicholas Renotte
9 How to Lemmatize Text - Part 4 - Python Yelp Sentiment Analysis
How to Lemmatize Text - Part 4 - Python Yelp Sentiment Analysis
Nicholas Renotte
10 How to Calculate Sentiment Using TextBlob - Part 5 - Python Yelp Sentiment Analysis
How to Calculate Sentiment Using TextBlob - Part 5 - Python Yelp Sentiment Analysis
Nicholas Renotte
11 How to Collect Business Reviews Using Python - Part 1 - Python Yelp Sentiment Analysis
How to Collect Business Reviews Using Python - Part 1 - Python Yelp Sentiment Analysis
Nicholas Renotte
12 How to Clean Text Based Data for NLP - Part 3 - Python Yelp Sentiment Analysis
How to Clean Text Based Data for NLP - Part 3 - Python Yelp Sentiment Analysis
Nicholas Renotte
13 How to Setup a IBM Watson Personality Insights Service - Part 1 - Watson Personality Insights
How to Setup a IBM Watson Personality Insights Service - Part 1 - Watson Personality Insights
Nicholas Renotte
14 How to Create a Customer Profile with IBM Watson - Part 2 - Watson Personality Insights
How to Create a Customer Profile with IBM Watson - Part 2 - Watson Personality Insights
Nicholas Renotte
15 Visualising The Profile   Part 3   Watson Personality Insights
Visualising The Profile Part 3 Watson Personality Insights
Nicholas Renotte
16 How to Plot Personality Insights Features at Lightspeed - Part 4  - IBM Watson Personality Insights
How to Plot Personality Insights Features at Lightspeed - Part 4 - IBM Watson Personality Insights
Nicholas Renotte
17 Getting Started With IBM Watson Studio Machine Learning - Part 1 - Predicting Used Car Prices
Getting Started With IBM Watson Studio Machine Learning - Part 1 - Predicting Used Car Prices
Nicholas Renotte
18 Upload and Visualize Data In IBM Watson Studio - Part 2 - Predicting Used Car Prices
Upload and Visualize Data In IBM Watson Studio - Part 2 - Predicting Used Car Prices
Nicholas Renotte
19 Clean Data and Feature Engineer in IBM Watson Studio - Part  3 - Predict Used Car Prices
Clean Data and Feature Engineer in IBM Watson Studio - Part 3 - Predict Used Car Prices
Nicholas Renotte
20 Using Watson Model Builder to Predict Car Prices - Part 4 - Predicting Used Car Prices
Using Watson Model Builder to Predict Car Prices - Part 4 - Predicting Used Car Prices
Nicholas Renotte
21 Deploy and Make Predictions With Watson Studio - Part 5 - Predicting Used Car Prices
Deploy and Make Predictions With Watson Studio - Part 5 - Predicting Used Car Prices
Nicholas Renotte
22 Getting Started With IBM Watson Discovery - Part 1 - Stock News Crawler
Getting Started With IBM Watson Discovery - Part 1 - Stock News Crawler
Nicholas Renotte
23 How to Run Advanced Queries with Watson Discovery - Part 5 - Stock News Crawler
How to Run Advanced Queries with Watson Discovery - Part 5 - Stock News Crawler
Nicholas Renotte
24 How to Run Search Queries with IBM Watson Discovery - Part 4 - Stock News Crawler
How to Run Search Queries with IBM Watson Discovery - Part 4 - Stock News Crawler
Nicholas Renotte
25 How to Understand the Watson Discovery Data Schema  - Part 3 - Stock News Crawler
How to Understand the Watson Discovery Data Schema - Part 3 - Stock News Crawler
Nicholas Renotte
26 How to Build a Watson Discovery Web Crawler - Part 2 - Stock News Crawler
How to Build a Watson Discovery Web Crawler - Part 2 - Stock News Crawler
Nicholas Renotte
27 AI learns what to do next using Tensorflow and Python
AI learns what to do next using Tensorflow and Python
Nicholas Renotte
28 Chatbot Crash Course for Absolute Beginners - Full 20 Minute Tutorial
Chatbot Crash Course for Absolute Beginners - Full 20 Minute Tutorial
Nicholas Renotte
29 Shopify Customer Service Chatbot using Python Automation
Shopify Customer Service Chatbot using Python Automation
Nicholas Renotte
30 Building a Reddit Keyword Research Chatbot
Building a Reddit Keyword Research Chatbot
Nicholas Renotte
31 Chatbot App Tutorial with Javascript Node.js [Part 1]
Chatbot App Tutorial with Javascript Node.js [Part 1]
Nicholas Renotte
32 Javascript Chatbot From Scratch with React.Js [Part 2]
Javascript Chatbot From Scratch with React.Js [Part 2]
Nicholas Renotte
33 Predicting Churn with Automated Python Machine Learning
Predicting Churn with Automated Python Machine Learning
Nicholas Renotte
34 Sales Forecasting in Excel with Machine Learning and Python Automation
Sales Forecasting in Excel with Machine Learning and Python Automation
Nicholas Renotte
35 Automate Budgeting with Python and Planning Analytics
Automate Budgeting with Python and Planning Analytics
Nicholas Renotte
36 AI vs Machine Learning vs Deep Learning vs Data Science
AI vs Machine Learning vs Deep Learning vs Data Science
Nicholas Renotte
37 Optimizing Marketing Spend using Linear Programming || Marketing Opt PT.1
Optimizing Marketing Spend using Linear Programming || Marketing Opt PT.1
Nicholas Renotte
38 Solving Optimization Problems with Python Linear Programming
Solving Optimization Problems with Python Linear Programming
Nicholas Renotte
39 Loading Data into Planning Analytics with Python || Marketing Opt PT.2
Loading Data into Planning Analytics with Python || Marketing Opt PT.2
Nicholas Renotte
40 Building Marketing Dashboards with Planning Analytics Workspace || Marketing Opt PT.3
Building Marketing Dashboards with Planning Analytics Workspace || Marketing Opt PT.3
Nicholas Renotte
41 Optimizing Resource Allocation with Docplex and Planning Analytics || Marketing Opt PT.4
Optimizing Resource Allocation with Docplex and Planning Analytics || Marketing Opt PT.4
Nicholas Renotte
42 Exploratory Data Analysis With Pandas || Python Machine Learning PT.1
Exploratory Data Analysis With Pandas || Python Machine Learning PT.1
Nicholas Renotte
43 Preparing Pandas Dataframes for Machine Learning || Python Machine Learning PT.2
Preparing Pandas Dataframes for Machine Learning || Python Machine Learning PT.2
Nicholas Renotte
44 Python Machine Learning with Scikit Learn - Regression || Python Machine Learning PT.3
Python Machine Learning with Scikit Learn - Regression || Python Machine Learning PT.3
Nicholas Renotte
45 Deploying Machine Learning Models with Watson Machine Learning || Python Machine Learning PT.4
Deploying Machine Learning Models with Watson Machine Learning || Python Machine Learning PT.4
Nicholas Renotte
46 Mind Blowing Machine Learning Apps with Node.JS and Watson Machine Learning || Python ML PT.5
Mind Blowing Machine Learning Apps with Node.JS and Watson Machine Learning || Python ML PT.5
Nicholas Renotte
47 Build FAST Machine Learning Apps with Javascript React.Js and Watson || Python ML PT.6
Build FAST Machine Learning Apps with Javascript React.Js and Watson || Python ML PT.6
Nicholas Renotte
48 Analyzing Twitter Accounts with Python and Personality Insights
Analyzing Twitter Accounts with Python and Personality Insights
Nicholas Renotte
49 Converting Speech to Text in 10 Minutes with Python and Watson
Converting Speech to Text in 10 Minutes with Python and Watson
Nicholas Renotte
50 Build a Face Mask Detector in 20 Minutes with Watson and Python
Build a Face Mask Detector in 20 Minutes with Watson and Python
Nicholas Renotte
51 AI Text to Speech in 10 Minutes with Python and Watson TTS
AI Text to Speech in 10 Minutes with Python and Watson TTS
Nicholas Renotte
52 Pandas for Data Science in 20 Minutes | Python Crash Course
Pandas for Data Science in 20 Minutes | Python Crash Course
Nicholas Renotte
53 Language Translation and Identification in 10 Minutes with Python and Watson AI
Language Translation and Identification in 10 Minutes with Python and Watson AI
Nicholas Renotte
54 Analyse ANY Conversation in 10 Minutes with Python and Watson Tone Analyser
Analyse ANY Conversation in 10 Minutes with Python and Watson Tone Analyser
Nicholas Renotte
55 Deep Reinforcement Learning Tutorial for Python in 20 Minutes
Deep Reinforcement Learning Tutorial for Python in 20 Minutes
Nicholas Renotte
56 NumPy for Beginners in 15 minutes | Python Crash Course
NumPy for Beginners in 15 minutes | Python Crash Course
Nicholas Renotte
57 Real Time Pose Estimation with Tensorflow.Js and Javascript
Real Time Pose Estimation with Tensorflow.Js and Javascript
Nicholas Renotte
58 Transcribe Video to Text with Python and Watson in 15 Minutes
Transcribe Video to Text with Python and Watson in 15 Minutes
Nicholas Renotte
59 Serverless Functions for TM1/Planning Analytics in 20 Minutes
Serverless Functions for TM1/Planning Analytics in 20 Minutes
Nicholas Renotte
60 Building a AI Budget Bot for Planning Analytics with Watson Assistant in 20 Minutes
Building a AI Budget Bot for Planning Analytics with Watson Assistant in 20 Minutes
Nicholas Renotte

This video provides a comprehensive introduction to the basics of Python programming for data science, covering variables, data types, lists, tuples, sets, and dictionaries. It provides practical examples and applications of these concepts in data science.

Key Takeaways
  1. Create a new Jupyter notebook and navigate to a specific folder
  2. Define and assign variables in Python
  3. Use type casting to convert between data types
  4. Create and manipulate lists, tuples, sets, and dictionaries in Python
  5. Apply CRUD framework to create, read, update, and delete variables and data structures
  6. Use dictionaries to store key-value pairs and access values using keys
💡 Dictionaries are a fundamental data structure in Python and are commonly used in data science to store key-value pairs, making it easy to access and manipulate data.

Related Reads

📰
AI CLI Tools Are Eating Each Other's Lunch
AI CLI tools are becoming increasingly similar, making it difficult to choose between them, and their failure patterns are identical, highlighting the need for more transparency and accountability in AI development
Dev.to · Tracepilot
📰
Loop Engineering: The Skill That Just Made Your AI Workflow Obsolete
Learn how loop engineering can automate AI workflows, making traditional prompting methods obsolete
Medium · Machine Learning
📰
We built a real-time Pokémon TCG AR overlay for live streams and open-sourced everything
Learn how to build a real-time Pokémon TCG AR overlay using a webcam, gaming PC, and open-source AI
Medium · Deep Learning
📰
I tested the new Claude Desktop on Linux - here's how it compares to rival apps
Learn how Claude Desktop on Linux compares to rival apps and its limitations with local AI
ZDNet

Chapters (5)

Introduction
6:48 Creating Variables
14:52 Data Types
57:21 Lists
1:08:20 Dictionaries
Up next
Copilot Cowork: Setup, Skills, Plugins & Pricing
Matt Tutorials
Watch →