I have a dataset of origin and destination coordinates that basically look like this:
import pandas as pd
import numpy as np
index = [1, 2, 3, 4, 5]
o_lt = pd.Series([19.285423, 19.285423, 19.639463, 19.631464, 19.631464], index = index)
o_lg = pd.Series([-99.126699, -99.126699, -99.094227, -99.123784, -99.123784], index = index)
d_lt = pd.Series([19.359331, 19.368288, 19.443874, 19.443874, 19.443874], index = index)
d_lg = pd.Series([-99.270102, -99.259745, -99.153412, -99.153412, -99.153412], index = index)
cluster = pd.Series([33, 33, 33, 33, 33], index = index)
cdmx_df = pd.DataFrame(np.c_[o_lt, o_lg, d_lt, d_lg, cluster], columns = ["origin_latitude", 'origin_longitude', 'destination_latitude', 'destination_longitude', 'cluster'])
print(cdmx_df)
My dataset contains 1,600,000 observations. So what I did is a k-means clustering and that is how I got the column cluster
.
Now what I want to do next is plot my observations in a map in folium
.
I want to observe both origin and destination, to see which routes are being demanded the most.
I am doing this with folium:
cdmx_map = folium.map.FeatureGroup()
for lat1, lng1, lat2, lng2, cluster in zip(cdmx_df['origin_latitude'],
cdmx_df['origin_longitude'],
cdmx_df['destination_latitude'],
cdmx_df['destination_longitude'],
cdmx_df['cluster'],):
cdmx_map.add_child(
folium.vector_layers.CircleMarker(
[lat1, lng1, lat2, lng2],
color = 'green',
fill = True,
fill_color = 'blue',
fill_opacity = 0.6,
tooltip = str(lng1) + ',' + str(lat1) + ',' + str(lat2) + ',' + str(lng2)
)
)
The problem with this code is that it only lets me plot using one coordinate :´( So it is not running.
Is there anyway to plot my destination coordinates and origin coordinates in a single folium map?