#!/usr/bin/env python # coding: utf-8 # In[1]: import pandas as pd import folium # In[2]: df = pd.read_csv('data/bfro_reports_geocoded.csv') df.head() # This is great! We have the observed column which has details of the observation, location details of where the observation happened, county, state, season the observation happened in, the report title, latitude and longitude, date etc. # # Let's take a look at the shape of the dataset. # In[3]: df.shape # 4,747 records. Not bad for a little analysis. # # Next let's see what the columns in the dataset are. # In[4]: df.columns # Ok, looks like we have plenty of geo data to plot maps with. Let's first start by looking at which states have the most observations. # In[5]: df['state'].value_counts() # Washington and California sure love their Bigfoot eh? # # For an analysis that's a little bit more intuitive, let's plot this out really quick. I'll use the Altair plotting library but you can use whatever you want. # In[6]: import altair as alt bf_states = alt.Chart(df).mark_bar().encode( x=alt.X('count(state):Q'), y=alt.Y('state:N', sort='-x') ) bf_states # Some of thes location frequencies make sense to me. Such as more wooded states there seem to be higher sighting volume. It is weird to me that Bigfoot doesn't appear in Alaska very frequently. Perhaps due to a lower population with which Bigfoot can be spotted? Who knows for sure. # # Now let's take a look at which season Sasquatch is seen in. # In[7]: bf_seasons = alt.Chart(df).mark_bar().encode( x='count(season):Q', y=alt.Y('season:N', sort='-x') ) bf_seasons # Looks like summer and fall are the big winners for Sassy sightings. I wonder if we see a similar trend in number of folks camping by season. I bet we do. Just a thought. # # Ok... ready for some maps? Me too! # # First things first, lets get a map centered on North America. For this part, let's use the slimmer dataset provided in `bfro_report_locations.csv` # In[8]: bf_locations = pd.read_csv('data/bfro_report_locations.csv') bf_locations.head() # This is good. We don't want the entire dataset while trying to manipulate some maps. # In[9]: folium.Map(location=[37.0902, -95.7129], zoom_start=4) # What I did above is passed latitude and longitude coordinates and a zoom parameter to the Map object. This tells folium where to center the map and at what zoom. If we set the zoom to 1 the map gets zoomed all the way out. # In[10]: folium.Map(location=[37.0902, -95.7129], zoom_start=1) # If we set the zoom to 20, we get a nice tight view of an "Industrial Area" in Dearing, Kansas. Never been there... seems nice. # # Why did I pick this location you ask? Turns out, this is really close to the center of the United States wher most of the BF sightings in the dataset took place. # In[11]: folium.Map(location=[37.0902, -95.7129], zoom_start=20) # Ok ok, this is all great but let's get some Sass locations in there. # # Next thing we need to do is learn how to place a marker. # In[12]: # This is our map lovingly centered on Dearing Kansas at a zoom of 15 kansas_map = folium.Map(location=[37.0902, -95.7129], zoom_start=15) # Add the marker to the map... folium.Marker(location=[37.0902, -95.7129]).add_to(kansas_map) # Display the map with the marker that's been added kansas_map # There you have it, a blue marker at the public access of some lake in Kansas. Sweet! # # Now to add all the locations that Bigfoot has been spotted at, we need to create a list of tuples containing latitude and longitude coordinates where Bigfoot has been spotted like this: # # `[(lat, long), # (lat, long), # (lat, long)...]` # In[13]: locations = list(zip(bf_locations['latitude'].values, bf_locations['longitude'].values)) locations[:5] # Showing first 5 locations as an example # Now we just need to use these tuples as marker placements for the map. # In[14]: bf_map = folium.Map(location=[37.0902, -95.7129], zoom_start=4) # Base Map of US (centered) # For each location in the list of lat and long tuples we created above: for location in locations: # Add a marker to the bf_map folium.Marker(location=[location[0], location[1]]).add_to(bf_map) bf_map # There you have it. That's a lot of Notorious B.I.G. Foot sightings. Even a couple in the Pacific Ocean! That's neat! At some point we'll need to examine those for validity but for now we'll just assume Bigfoot is better known as Sassy Surfer out there. # In[14]: # In[15]: bf_map.save('bf_locations_markers.html') # In[16]: bf_map.save('bf_locations_markers.jpeg') # In[ ]: