Resolve vehicle_type_id → form factor / propulsion / range onto a vehicles frame.
Turns "where are the e-bikes?" into a filter: out[out.form_factor == "bicycle"] etc.
Left join on vehicle_type_id; the catalogue's system_id is dropped to avoid a clash.
See Also
filter_vehicles : Filter on the resolved attributes.
ebikes : The electric-only shorthand.
join_pricing : Resolve pricing onto the same vehicles.
Examples:
>>> import pandas as pd
>>> vehicles = pd.DataFrame({"bike_id": ["v1"], "vehicle_type_id": ["t1"]})
>>> types = pd.DataFrame({"vehicle_type_id": ["t1"], "form_factor": ["bicycle"]})
>>> join_vehicle_types(vehicles, types)["form_factor"].tolist()
['bicycle']
Source code in src/gbfs_toolkit/analytics/frames.py
| def join_vehicle_types(vehicles: pd.DataFrame, vehicle_types: pd.DataFrame) -> pd.DataFrame:
"""Resolve ``vehicle_type_id`` → form factor / propulsion / range onto a vehicles frame.
Turns "where are the e-bikes?" into a filter: ``out[out.form_factor == "bicycle"]`` etc.
Left join on ``vehicle_type_id``; the catalogue's ``system_id`` is dropped to avoid a clash.
See Also
--------
[`filter_vehicles`][gbfs_toolkit.filter_vehicles] : Filter on the resolved attributes.
[`ebikes`][gbfs_toolkit.ebikes] : The electric-only shorthand.
[`join_pricing`][gbfs_toolkit.join_pricing] : Resolve pricing onto the same vehicles.
Examples
--------
>>> import pandas as pd
>>> vehicles = pd.DataFrame({"bike_id": ["v1"], "vehicle_type_id": ["t1"]})
>>> types = pd.DataFrame({"vehicle_type_id": ["t1"], "form_factor": ["bicycle"]})
>>> join_vehicle_types(vehicles, types)["form_factor"].tolist()
['bicycle']
"""
cat = vehicle_types.drop(columns=["system_id"], errors="ignore")
return vehicles.merge(cat, on="vehicle_type_id", how="left")
|