-
Introduction 1
-
Lecture1.1
-
-
Getting the Data 4
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
-
Location Groups 3
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
-
Creating the New Data 3
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
-
Mapping the Data 3
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
Map Basics
Let’s first get our map of Boston. We aren’t going to draw anything yet.
import pandas as pd
import numpy as np
import gmplot
def Create_Map():
gmap = gmplot.GoogleMapPlotter.from_geocode("Boston")
gmap.draw("Boston_Real_Estate.html")
Create_Map()
The line gmap = gmplot.GoogleMapPlotter.from_geocode(“Boston”) creates a map object with Boston as it’s center. The draw function creates the file; check it out in your folder and you should see a regular Boston map.
To draw a square, we are going to need 4 points. The way we feed these points is an array of x coordinates, and an array of y coordinates to match. To draw a square where we will draw our grid, this code will work.
latMax = 42.39615117
latMin = 42.23108386
lonMax = -70.92757284
lonMin = -71.18485204
def Create_Map():
gmap = gmplot.GoogleMapPlotter.from_geocode("Boston")
xPoints=[latMax,latMin,latMin,latMax]
yPoints=[lonMin,lonMin,lonMax,lonMax]
gmap.polygon(xPoints, yPoints, color="#ff0000")
gmap.draw("Boston_Real_Estate.html")
Create_Map()
Let’s pull in our map data.
MapData = pd.DataFrame.from_csv("MapData.csv", encoding="UTF-8")
Challenge
Plot each individual square of the grid for our boston data.
Prev
Introduction
Next
Finishing the Map