Leaflet Webmap of my Tweets @ #ValleyFair this Sunday, June 10th, 2018.

Review the imported csv data using Pandas

In [1]:
# Read & checkout csv as a pandas dataframe
import pandas
csvFile = r'..\notebooks2\twitterposts\tweethistory_#ValleyFair_20180611.csv'

dataFrame = pandas.read_csv(csvFile)
dataFrame
Out[1]:
created_at tweet_id text name screen_name language lat long
0 6/10/2018 22:04 1.005930e+18 Heading #home for the day at #ValleyFair. I th... Kim Sundeen KSundeen en 45.249559 -93.024857
1 6/10/2018 21:40 1.005930e+18 #ValleyFair had a kick ass time today!!! #fair... Kim Sundeen KSundeen en 44.798738 -93.453917
2 6/10/2018 20:46 1.005910e+18 #ValleyFair #ThunderCanyon here we come!!! htt... Kim Sundeen KSundeen en 44.800471 -93.461790
3 6/10/2018 20:19 1.005910e+18 #ValleyFair #SteelVenom is totally the best so... Kim Sundeen KSundeen en 44.797843 -93.451812
4 6/10/2018 19:49 1.005900e+18 #ValleyFair I’m Batman!! I’d totally put on a ... Kim Sundeen KSundeen en 44.799605 -93.457564
5 6/10/2018 19:12 1.005890e+18 #ValleyFair #PowerTower it up!! https://t.co/b... Kim Sundeen KSundeen en 44.799492 -93.456749
6 6/10/2018 18:48 1.005880e+18 #ValleyFair #WildThing....it’s a looooong way ... Kim Sundeen KSundeen en 44.798558 -93.458715
7 6/10/2018 18:47 1.005880e+18 #ValleyFair #WildThing seems to be the only on... Kim Sundeen KSundeen en 44.798766 -93.458326
8 6/10/2018 18:30 1.005880e+18 #ValleyFair #Excalibur was comfortable....not ... Kim Sundeen KSundeen en 44.799441 -93.461949
9 6/10/2018 18:17 1.005880e+18 #ValleyFair #renegade craziness....this was wa... Kim Sundeen KSundeen en 44.800434 -93.460883
10 6/10/2018 17:58 1.005870e+18 #ValleyFair #LoopingStarship!!! Hope the count... Kim Sundeen KSundeen en 44.800018 -93.459936
11 6/10/2018 17:42 1.005870e+18 #ValleyFair #highRoller at the top 🤭 https://t... Kim Sundeen KSundeen en 44.799940 -93.458039
12 6/10/2018 17:38 1.005870e+18 #ValleyFair here we goooooo!!!! #highroller ht... Kim Sundeen KSundeen en 44.800383 -93.457784
13 6/10/2018 17:31 1.005870e+18 #ValleyFair no lines for the high roller!!! Ye... Kim Sundeen KSundeen en 44.800191 -93.457698
14 6/10/2018 17:13 1.005860e+18 #ValleyFair thee corkscrew!!! https://t.co/FqM... Kim Sundeen KSundeen en 44.799272 -93.455406
15 6/10/2018 17:09 1.005860e+18 #ValleyFair #dinosaurs are alive!! https://t.c... Kim Sundeen KSundeen en 44.799616 -93.454610
16 6/10/2018 17:06 1.005860e+18 #ValleyFair fun is starting!!! https://t.co/L8... Kim Sundeen KSundeen en 44.798737 -93.454312
17 6/10/2018 16:49 1.005850e+18 #ValleyFair fun!!! Starting the day. https://t... Kim Sundeen KSundeen en 44.798738 -93.453917
18 6/10/2018 15:32 1.005840e+18 #Fun times!! Trip to the cities for #ValleyFai... Kim Sundeen KSundeen en 44.798551 -93.451740

Use json to add to leaflet map

Install the folium library using conda. It wasn't in the normal conda library, so I searched the library name at Anaconda: https://anaconda.org/search?q=folium. This is the library: https://python-visualization.github.io/folium/installing.html

> conda install folium -c conda-forge
In [6]:
import folium
import numpy as np
import pandas
from folium.plugins import MarkerCluster
import os

# df=pandas.read_csv(r'..\notebooks2\twitterposts\tweethistory_trail_510_since2018-05-03.csv')
df=pandas.read_csv(r'C:\Users\kimhs\Google Drive\Work_related\notebooks2\twitterposts\tweethistory_#ValleyFair_20180611.csv')
# print(df)
lats = df['lat']
longs = df['long']
tweet = df['text']

# Try to add in address later
# fullAddress = str(list(zip(address, city, state, zipcode)))
# print(fullAddress)

#-----------------------------
# With Plotname -- broken :..( 
# locationInfo = list(zip(plotnames, lats, longs))
# popups = ['Plotname: {}; <br>long: {}<br>lat: {}'.format(plotnames, longs, lats) for (plotnames, lats, longs) in locationInfo]
#-----------------------------

# No Plotname
locationInfo = list(zip(lats, longs))
popups = ['<br>long: {}<br>lat: {}'.format(longs, lats) for (lats, longs) in locationInfo]

# Get list of lats/longs to feed the popups. 
# Add different tiles: https://deparkes.co.uk/2016/06/10/folium-map-tiles/
m = folium.Map(
    location=[np.mean(lats), np.mean(longs)],
#     tiles='Cartodb Positron',
#     tiles='MapQuest Open Aerial',
    zoom_start=13
)

# Create new Leaflet MarkerClusterGroup from js lib
marker_cluster = MarkerCluster(
    name='Valley Fair Tweets',
    overlay=True,
    control=True,
    icon_create_function=None
)
In [7]:
# Add all locations & assign popups to the MarkerClusterGroup
for k in range(len(locationInfo)):
#     plotname = locationInfo[k][0]
#     location = locationInfo[k][1], locationInfo[k][2]
    location = lats[k], longs[k]
    marker = folium.Marker(location=location)
#     popup = '{}<br>lat:{}<br>long:{}'.format(plotname, location[0], location[1])
    popup = 'lat:{}<br>long:{}'.format(location[0], location[1])
    folium.Popup(popup).add_to(marker)
    marker_cluster.add_child(marker)

marker_cluster.add_to(m)

folium.LayerControl().add_to(m)

m.save(outfile='valleyfair.html')
m
Out[7]: