Visualizing geospatial data#
Generating maps from data is a nice way to generate additional insight into data and make it instantly accessible and understandable.
Visualizing geospatial data is a powerful tool for gaining insights and understanding patterns in data.
By mapping data onto a geographic space, it is possible to uncover relationships and trends that might otherwise be difficult to discern. Whether tracking the spread of a virus across the globe, identifying traffic jams in a city, or analyzing consumer behaviour across different regions, geospatial visualization can reveal patterns and relationships that might not be immediately apparent from raw data alone.
With advances in technology and data analytics, creating maps and visualizations has become easier and more accessible than ever, making it a valuable tool for researchers, policymakers, and businesses.
How To#
import pandas as pd
df = pd.read_csv("data/housing.csv")
df.head()
longitude | latitude | housing_median_age | total_rooms | total_bedrooms | population | households | median_income | median_house_value | ocean_proximity | |
---|---|---|---|---|---|---|---|---|---|---|
0 | -122.23 | 37.88 | 41.0 | 880.0 | 129.0 | 322.0 | 126.0 | 8.3252 | 452600.0 | NEAR BAY |
1 | -122.22 | 37.86 | 21.0 | 7099.0 | 1106.0 | 2401.0 | 1138.0 | 8.3014 | 358500.0 | NEAR BAY |
2 | -122.24 | 37.85 | 52.0 | 1467.0 | 190.0 | 496.0 | 177.0 | 7.2574 | 352100.0 | NEAR BAY |
3 | -122.25 | 37.85 | 52.0 | 1274.0 | 235.0 | 558.0 | 219.0 | 5.6431 | 341300.0 | NEAR BAY |
4 | -122.25 | 37.85 | 52.0 | 1627.0 | 280.0 | 565.0 | 259.0 | 3.8462 | 342200.0 | NEAR BAY |
import folium
m = folium.Map(location=[df.latitude.mean(), df.longitude.mean()])
m
m = folium.Map(location=[df.latitude.mean(), df.longitude.mean()], zoom_start=6)
for i, row in df.sample(15).iterrows():
folium.Marker([row.latitude, row.longitude], tooltip=row.ocean_proximity).add_to(m)
m
from folium import plugins
heatmap = folium.Map(location=[df.latitude.mean(), df.longitude.mean()], zoom_start=6, tiles='Stamen Toner',)
# plot heatmap
heatmap.add_children(folium.plugins.HeatMap(df[['latitude', 'longitude']].values, radius=15))
heatmap
folium.Choropleth(
)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[6], line 1
----> 1 folium.Choropleth(
2
3 )
TypeError: __init__() missing 1 required positional argument: 'geo_data'
Exercise#
Change the basemap and chose different marker types.