Real Estate Data Visualization Using Map in Python
Today we learn how to easily visualize real estate data on an interactive world map in Python.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: https://www.neuralnine.com/books/
💻 The Algorithm Bible Book: https://www.neuralnine.com/books/
👕 Programming Merch: https://www.neuralnine.com/shop
💼 Services 💼
💻 Freelancing & Tutoring: https://www.neuralnine.com/services
🌐 Social Media & Contact 🌐
📱 Website: https://www.neuralnine.com/
📷 Instagram: https://www.instagram.com/neuralnine
🐦 Twitter: https://twitter.com/neuralnine
🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/
📁 GitHub: https://github.com/NeuralNine
🎙 Discord: https://discord.gg/JU4xr8U3dm
What You'll Learn
The video demonstrates how to visualize real estate data on an interactive world map using Python, specifically utilizing libraries such as Folium for map visualization and Pandas for data manipulation.
Full Transcript
what is going on guys welcome back in this video today we're going to learn how to create interactive visualizations of real estate data using a map in Python so let us get right into it not a GED all right now before we get started with the actual tutorial I would like to show you what we're going to end up with here as a motivational preview up front this is the final result you can see it's an interactive map I can move around here uh I can zoom out to see the entire world and I can also zoom into these data points here now you can see that all the data points in this case right now are in California this is because I'm right now visualizing the California Housing data set of course if you have a European data set or an Asian data set or something like that you're going to see the data points in the respective places uh all you need for this is you need some data that contains coordinates and some additional information to determine the color and the size of the individual data points uh so here for example I have uh the individual data points colored based on the price and the size of the data points is determined by the average number of rooms uh in the area so since this is the California Housing data set the individual data points are not actually individual houses there're actually uh areas with median income and uh median or average number of rooms and median house price and so on but of course you can use any data set containing individual houses individual Apartments areas whatever you want actually doesn't even have to be real estate data you can uh visualize any geographical data set uh with the knowledge that you're going to learn about in this video today so this is what we're going to build today an interactive visualization we can also click on the individual data points to get some more information about them and yeah now we're going to need a couple of external python packages for this video today so we're going to open up the command line and we're going to install the following packages using pip so either pip or pip 3 install and we're going to need pandas because we're working with data frames we're going to need mat plot lip for parts of the visualization uh we're going to need psychic learn but only if you also want to use the California Housing data set if you want to use your own data set just load it with pandas read CSV if it's a CSV file uh read Excel if it's an Excel file read Json if it's a Json file and so on the important thing about your data set is it has to contain coordinates it has to contain latitude and longitude so um the location data because you need of course to place the individual data points on the map so you need to know where to place them and this is specified as latitude and longitude so you need to have the coordinates everything else in your data set can be different and you can use different features for the color for the size and so on but you need to have the coordinates uh and the fourth package is called folium this is what we're going to use for the actual map visualization so this is the package that is going to do all the uh geographical stuff for us uh all right now once you have these packages installed we're going to import pandas SPD we're going to import matplot lip. pip plot splt we're going to import matp lip do colors ASM colors we're going to say from Psychic learn I want to import from the data sets the fetch California Housing function to download the California Housing data set um and I also want to import obviously folium and from folium I also want to import plugins uh which is going to allow us to have a mini map all right so these are the Imports and now what we're going to do is we're going to get the data and we're going to decide on how we want to visualize the individual data points now for this video I'm going to visualize the price as the color and the size as the size of the bubble now size in this case means average number of rooms because we don't have really a size feature in the uh California Housing data set but if you have a data set containing individual houses you might have something like uh the area of the house something like Square met or Square photo something like that and the price of the individual house I'm going to use here the median house value of the area and the average number of rooms for the size so we're going to say here data equals fetch California Housing and we're going to pass ASF frame equals true to get it as a data frame and then we're going to also create a map instance so we're going to say m equals folium do map and what we want to do is we want to Center the map around the data points that we have so what we're going to do is we're going to take the coordinates of the data set and we're going to calculate the mean coordinates so the latitude and longitude mean values are going to be the center of our map so for this we're going to say location equals uh data latitudes do mean and data longitude do mean and I also want to set a zoom factor of six in the beginning so this is our map now now in order to visualize our uh price or our room numbers as color and size we need to normalize them to make this easier so we want to have the price values going from 0o to one in order to be able to choose a color uh value from 0 to one zero being uh green for a very cheap house and or cheap area and one being red for a very expensive area and in between we have some yellow and for the size we also want to have a certain range and it's easier to work with values between zero and one instead of just using the raw values that we have so in order to be able to normalize the values we need to define or we need to get the minimum and maximum Valu so I'm going to say here price Min price Max is going to be equal to data and the feature is called met house Val so median house value um and I want to get the minimum and I want to get the maximum so data met house Val and then Max uh and the same thing for the rooms so I'm going to say here size Min and size Max is going to be equal to data uh average rooms. Min data average rooms. Max and uh these are the values that we're going to use for the normalization now in order to visualize the individual data points we going to iterate over our data frame so I'm going to say here for index that we don't need so I'm going to use a placeholder and row in DF or actually data. itos uh we're going to do the following we're going to calculate the normalized price and we're going to turn it into a color so the normalized price is equal to taking the price so taking the row data uh median house value of the current data point um and subtracting from it the minimum price and dividing by the maximum price minus the minimum price so by the price range and to turn this now into a color we're going to say color equals PLT so we're going to use mat PL lip uh PLT uh CM which I think stands for color map and we're going to choose the red yellow green color map and we're going to pass your one minus normalized price uh one minus to inverted because we want it to go from green to Red Green indicating small values red indicating large values and because of that uh we invert it because it goes from red to Green we want it to go from green to Red so this is how we determine the color of the bubble or of the data point then we're going to say normalized rooms is equal to the same thing for the rooms so row average rooms minus size minimum divided by the size range so size maximum size minimum and um that is our normalized room number here now what we also want to have is we want to have a popup with some information so I'm going to say popup uh info is going to be an F string I'm going to make this a multi-line string and this string will contain just uh some information about about the area or in your case if you have your own data set about the house so median house value is going to be obviously the row met house Val feature um up to two decimal places then I want to use a line break and I'm going to say the average rooms is going to be row average rooms I also want to use a line break here then we're going to say population of the area is going to be row population it feel free to add whatever you want here whatever your data set has or whatever you want to use from the data set uh we're going to go with population line break as well and then we want to go finally with the median income of the area now we don't need features like ocean proximity because we can see that visually so we don't need to really put them here in the popup info uh so the median in income is going to be in dollars and it's called met Inc and we want it up to to decimal places and that's it so this is our popup info string and now what we want to do is we want to create the actual Circle so we're going to say folium do Circle marker and here now we're going to pass the following information the location is going to be a list containing the latitude and long longitude so the coordinates of the individual data point um the radius of the data point is going to be a basis of five so it's going to be five uh at least plus 20 times the normalized rooms so depending on the number of rooms we're going to have a multiplier of 20 the minimum size is going to be five if this is uh zero but I don't think that any area can have zero room so it's going to be to be more than five usually um and then we're going to go and say color is equal to m colors. 2 hex so we're going to take the color value that we get here this is going to be uh a tupal of four values I think we have RGB and then the opacity so what we want to do is we want to convert RGB to hex so we want to exclude the opacity because we just uh want to have the RGB values and we want to turn them into a hex uh color code so we're going to say color and we only want to take the first three values so RG and B uh red green blue we also want to set fill to true we want to say the fill color is going to be the same as the other one so it's going to be two hex color three and the opacity now for filling so the fill underscore opacity will be 0.7 70% here and now the popup will be equal to folium do popup containing the popup information and having a maximum width of 300 this is our Circle marker and now all we need to do is we need to add it to our map so just add a DOT uh add to M and then we have our Circle marker on the map and we do this for all the data points and the last thing we need to do is in the end we want to enable the mini map so we need to say plugins. mini map. add2 M so we add a mini map to our map and finally m. safe uh let's call this real estate. HTML and that is our actually we need to use the Constructor here so this is actually a call uh and that is now our visualization code so we just load the data we create a map we normalize the price and the number of rooms we determine the color based on that we add a pop-up string we create a marker for every single data point with the location with the rooms uh or with the size based on the rooms with the color based on the price uh and then we add a mini map we export everything as an HTML file so now I can just run this it's going to take actually what's the problem here latitude uh did I misspell it actually not so where is this actually it's here data oh sorry I made one mistake we get this as a frame but to actually get the data frame we need to say do frame so we get the data set and we want to get the data frame of the data set so I'm going to run this again now it should work and it's going to take some time it's going to export an HTML file which we can then open up in the browser as an interactive uh visualization now I'm already going to open this in files here and you can see that the file is being created already uh now it's done and I'm going to open this in Chrome because in Firefox it's quite laggy especially when I'm recording and there you go we have our visualization you can see the mini map or actually you cannot see the mini map because my camera is blocking it there you go you can see the mini map here um I can move around I can zoom out a lot as you saw in the preview already I can see the entire world I can also zoom in quite a bit so I can actually go quite uh deep into these data points I can go to the streets and individual houses and so on um and uh also I can click on the data points to get the popup information so yeah this is how you can easily create interactive visualizations of real estate data or any geographical data if you have any data containing coordinates and additional information for the styling you can make a visualization like this using fume using Python and yeah so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you in the next video and bye for
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from NeuralNine · NeuralNine · 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
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: Python for Data
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Beyond the Credit Score: What 1.3 Million Loans Reveal About Who Actually Repays
Medium · Data Science
The Biotech Translation Gap: Where Clinical Success, Capital, and Unmet Need Diverge
Medium · Data Science
The AI Revolution That Won’t Fire Your Data Analysts
Medium · Data Science
Data Quality & dbt : Automatiser la gouvernance avec Python (Partie 2/5)
Medium · Python
🎓
Tutor Explanation
DeepCamp AI