Python Data Types | Real Estate Analytics

In this video, we will cover a Python data types, you will learn how to work with numbers, strings, and Boolean values. We will use real estate examples for each.

Video Block
Double-click here to add a video by URL or embed code. Learn more

Ariel Herrera 0:00

In this video, we will cover a Python data types, you will learn how to work with numbers, strings, and Boolean values. We will use real estate examples for each. Let's jump into the data types notebook from our table of contents. What are data types. In this image from real Python, we can see a brief overview of what data types are. In the last section, we created our first variable that held a string called Hello world, we can see string here in the bottom left hand corner of the image. We will touch more on strings in this lesson. For first let's cover integers. In real estate, it is common to work with a lot of numbers. This includes metrics like calculating mortgage payments, taxes amount, and for real estate investors cash flow for first integer, let's create a data object that holds an integer value for rent. So I'm going to type in here the variable name, which will be rent. And let's make it simple and have this integer value as 1000. Now we can print our rent value, hit Enter to go to the next line. And then we could start our print statement.

Now we can click enter, here, our output is our rent value is 1000. And we did this by putting it into a string. And I haven't explained this yet. But this is actually a neat way for us to enter variables into our strings, we could use these brackets, then in the syntax we could put format, which will hold all the variables that we want to input in this string. It makes it a little bit cleaner when we have a lot of variables to work with. Now that we've created our first integer variable, let's actually add to it in Python, we can add, subtract, multiply and divide our numbers. Let's imagine that we're real estate investors. Our property rent is currently $1,000. And we have a pet fee of $50. So how do we calculate our total income, that would be rent plus pet fee. So in this case, let's first create our variable called pet fee. Now by using a plus, we can add rent and pet fee. And

Unknown Speaker 2:31

here we see our

Ariel Herrera 2:32

total income is $1,050. Now of course, we're not going to actually pocket all of that, we likely had to have some taxes involved. So let's imagine that for our income 10% gets taxed out. So let's now create a new variable that's going to hold this 10% value, we will call this taxable income. Let's set this value to 0.10. This will represent 10% of our income will be taxable. Now let's calculate what that actual tax value is, we need to again add our rent and pet fee and then multiply it by this taxable income to multiply we will use star.

What we just did is we added rent plus pet fee, then we multiply by a taxable income, which was 10%. Or in this case, point one zero. The reason why we added parentheses around rent and pet fee is we want to add the total income before we do any of the multiplying. This is simple math, let's print what our total income will be. Now that we have the taxable expense, this will be the rent plus pet fee minus taxable expense.

So our total income here is $945. Sometimes when I go back into my code, I'm a little bit lost of why did I actually do this. So it's important to either add comments, which is with the number sign here, that tells Python not to execute that as a piece of code, or I like to add print statements. So I could be reminded as to what this value is. So let's add a print statement. Around this. We're going to say total income after taxes. Now we could see our total value. And if we want to understand our type of variables, we can also print that as well. We will just have to use parentheses around our variable and have type in front. I'll show you how to do So right now.

By wrapping our variable and type, Python allows us to see what the type of our variable is. And the first case, it's an integer, as we saw when we created it for rent, and for pet fee, these were both integer values. Dex is a float value, what is float, float basically means any variable, that's a number that has decimals afterwards, we could also see that beforehand, when we calculate a total income after taxes, it has dot zero at the end. So whenever we mix integers and floats, they automatically become float values. Awesome. Let's jump down into strings, which are pretty familiar with from our last section. But let's now comment out this code. In order to comment out code, you will need to highlight everything in the cell. And then you can do Command forward slash to uncomment, a large section of code. Now we can run this section of code here, what we have located in the cell are four different examples of how you can write different strings. And the first one is just with single quotes. Second is with double quotes. So we have here the double quotes, and then the single quotes, then we also have creating strings with triple quotes. That's another way to do so. And when we do that, with triple quotes, we could see that we actually can have double quotes within it, and I'll show up in our string. Then lastly, we can also do multi lines, where if we use triple quotes, we have here real estate then another line for another line life. So these are just different ways that you can write strings. For our use case, we're likely just going to stick to the top two, where we're use single or double quotes in order for us to create our strings. Now what if we want to access values of our strings? Here, we could see in this example, geeks for geeks is one long string. And then we have values underneath. These represent the characters. So in this case, G is Element Zero is the first element, which is a little bit different in Python doesn't start with one, it starts with zero. And then here we goes all the way up to 12. And total, there are 13 characters that make up this one word, that in the second row, we can go backwards as well. So if we wanted to select the s at the very end for geeks, for geeks, we could either select it by labeling 12 or indexing negative one because it's the last item in the list. K is the second to last item in the list, which is why it's negative two. This will make more sense as we go through our example here. So in this variable called S, which is short for street, I have a made up address called 123 Main Street in Miami, Florida 33990 as the zip code, let's run this cell. And now I want you to see how we can actually access different parts of our string. So what if we want to get just the first character, so we want to index zero because that will be the first character just like we have in this example here. So we're going to put our variable name for a string, which is s. And then to index, we're going to use these brackets,

specifically square brackets, and we're going to enter the element that we want to access which is zero. Now we can run the cell. And if we look, first character of string is one. And if we go back to our string, that is true, because one represents 123 Main Street, and it's the first variable that we see here. Now what if we want to get the last variable in our string? I'm not sure how many characters this is, this is pretty long are we going to count each and every one so we get to the last value? No, as we see above, in this chart, we can just access the last character by always putting negative one as our index. So let's do that here. We will put our string again, our variables S and then in the square brackets, negative one. Now let's run this cell. And now we see the last character of the string is zero. And if we look back at our string, we have the zip code at the end and the zip code ends at zero So Python successfully got the last character of the string that we expected. Now what if we wanted to know how long the string is to begin with, maybe we're building out some type of app, and someone is entering an address, what if they enter an address with 500 characters, that's highly unlikely, probably some type of error. And we want them to know, you need to have a length of a string that is under a certain amount. So in order to get length of string, Python has a really neat operator called Len. And you use parentheses to the input whatever string that you want within it. So in our case, our variable s. Now we can run Shift Enter. And we see here that the total length of the string is 28 characters. So I bet, if I were to change this, from negative one to 27, we would also get that zero. And if we run that, yes, we do. But of course, we wouldn't have known that it was 27 characters. If we didn't use length first, knowing the first and last character of a string can be useful, but usually not as much. Usually, we want to actually capture longer parts of our string. So by scrolling down in the next section, we want to be able to get the street name. So the street name here is 123 Main Street. We don't really care about anything else. In this example, how do we index this? Well, let's actually count out what the characters are. So 01 234-567-8910. Now, if we go back to street name, we would do us and then starting at zero to 10. And run this, we now get our street name. And as you can see, I missed one of the elements, it should actually be 11. And I'll show you down the line in future lessons when we use list of how we can more easily break this out. But as of now, another way that we can get just the street is we don't need to tell Python to start at zero, it automatically expects that. So we can do instead is add our square brackets, the colon, and then 11 to stop at element 11. And now we also get street name. Let's try to get just the zip code. So I'm going to change this statement here to zip code, enter in our variable, and sort of us counting all the way down to where zip code starts, we could use this backwards logic, we know that the element for ZIP codes is five characters in the US of code is always five different characters. So we could do negative five to get just the zip code. So let's start by adding our square brackets, negative five, want to start at element negative five and get everything after. So we add the colon afterwards. Now let's do Shift Enter. And we got our zip code. Pretty neat. I know it is a little bit about list in future sections. But let's actually do on right now. So we could see how we can make this more dynamic. So let's print our address, we could just do s here and play. So we have 123, Main Street, Miami, Florida 33990. And in order for us to just capture the street, city and state separately, we can use the Split function in Python. So we enter in our variable at a dot and then split an open parenthesis.

Python now split our string automatically through spaces. That's what happens when you don't answer anything in here. But in our case, we care about commas. So let's put single quotations and a comma, rerun the cell. And now we could see that our string is broken out into three different sections based on where the comma occurred. So we have 123 Main Street as our first one. And we want to capture that. So how do we do that with the list, we can actually copy this answer at the bottom and selecting elements in a list is pretty much the same as with a string. So if he wants to select the first element, we will use zero. So let's do our square brackets. enter zero run this cell. And now we have 123 Main Street. This was a more dynamic way to be able to capture the street. Lastly for this section, let's tackle bullions bullions are very simple, unlike numbers that can hold so many values and strings that can be many different variations. bullions only have two values, true or false, Let's uncomment the code that we have here. So we can highlight everything, and then command forward slash, and do that for the next two cells as well. What I have written out in this first cell is a function which we haven't touched yet, but we will in future videos, I just want you to get an understanding of what a Boolean actually does. So in our scenario, we are landlords reviewing rental applications for our open vacancy, we want to automatically reject rental applications based on credit scores below 600. There are only two outcomes. If an applicant passes our credit score criteria, then it will be true. If they do not then it is false. So we have a function. And we have a statement, which says if the applicant score is less than 600, then unfortunately, they do not pass. So we create our Boolean here to our variable pass credit score, and we set it to false else, which means the credit score is higher than 600, then the credit score does pass. So we set our variable to true. So our two options here false and true, are the only values that a Boolean can have. Now in our next cells, we're going to check if an applicant does pass based on their score that we have inputted here, let's run our cell up top. And let's run the second cell with an applicant score of 700. We store this variable as a result, and we could see that our return value is true, which is our Boolean. In this case, the applicant had a score greater than 600. So they do pass. Now on the next one, their credit score is five at what do you think is going to be returned? If you've said false, then you were correct. Awesome. Now we've covered Boolean with a real world example. And in total, we've covered integers, as well as strings. And we also got a sneak peek into LIS conditional statements and functions, which we're going to explore in the following lessons. Now if you want a deeper dive into any of these topics within the lessons, then scroll all the way down to the bottom because I offer in depth videos from other professionals on Python specifically for this one is data types. All right, I'll see you in the next lesson. want full access to the introduction to real estate Data Analytics course. Then sign up for the course in the link below. You will learn Python programming all with real estate related examples. This includes web scraping, retrieving data from sources like Zillow, realtor, Redfin, Yahoo Finance, US census, and more. If you haven't already, check out the introduction video to the course on YouTube to get a full understanding of what the course has to offer. Also, members of the free tech and real estate group on Facebook receive a 20% off the course seeing the next lesson.

Transcribed by https://otter.ai

Previous
Previous

Python Lists, Tuples, Dictionaries | Real Estate Analytics

Next
Next

Introduction to Python | Real Estate Analytics