Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- entity_id lat lon time
- 1001 34.5 14.2 4:55 pm
- 1001 34.7 14.5 4:58 pm
- 1001 35.0 14.6 5.03 pm
- 1002 27.1 19.2 2:01 pm
- 1002 27.4 19.3 2:08 pm
- 1002 27.4 19.9 2:09 pm
- import pandas as pd
- import numpy as np
- from geopandas import GeoDataFrame
- from shapely.geometry import Point, LineString
- # Zip the coordinates into a point object and convert to a GeoDataFrame
- geometry = [Point(xy) for xy in zip(df.lon, df.lat)]
- df = GeoDataFrame(df, geometry=geometry)
- # Aggregate these points with the GroupBy
- df = df.groupby(['entity_id'])['geometry'].apply(lambda x: LineString(x.tolist()) if x.size > 1 else x.tolist())
- df = GeoDataFrame(df, geometry='geometry')
- df = df.groupby(['entity_id'])['geometry'].apply(lambda x: LineString(x.tolist()) if x.size > 1 else x.tolist())
Add Comment
Please, Sign In to add comment