Skip to content

Input/Output

API Description
load_geolife_trajectories Load Microsoft GeoLife .plt trajectory files into a TrajDataFrame.
read Read a trajectory table from disk and return a TrajDataFrame.
write Write a trajectory dataframe to disk.

fastmob.io.file.load_geolife_trajectories(path, user_ids=None, **kwargs)

Load Microsoft GeoLife .plt trajectory files into a TrajDataFrame.

Parameters:

Name Type Description Default
path str

local path of the directory 'Geolife Trajectories 1.3/'

required
user_ids list

list of user IDs to load. If empty or None, all users are loaded.

None
**kwargs dict

Additional keyword arguments passed to the TrajDataFrame constructor. encoding (default "utf-8") is applied when reading each .plt file and is not forwarded to TrajDataFrame.

{}

Returns:

Type Description
TrajDataFrame

a TrajDataFrame with uid (string), lat/lng (float64), and datetime (parsed as timestamp[us]) columns.


fastmob.io.file.read(filename, **kwargs)

Read a trajectory table from disk and return a TrajDataFrame.

CSV and delimited text files are read with pyarrow.csv.read_csv; parquet files are read with pyarrow.parquet.read_table.

Parameters:

Name Type Description Default
filename str

path and name of the file to read.

required
**kwargs dict

For parquet files, passed to pyarrow.parquet.read_table. For CSV/ delimited files, passed to fastmob.utils._arrow_io.read_delimited (accepts delimiter, encoding, header, column_names, plus any pyarrow.csv.ConvertOptions keyword).

{}

Returns:

Type Description
TrajDataFrame

object loaded from file.


fastmob.io.file.write(tdf, filename, **kwargs)

Write a trajectory dataframe to disk.

CSV and delimited text files are written with pyarrow.csv.write_csv; parquet files are written with pyarrow.parquet.write_table. The input is materialized as a pyarrow.Table via Narwhals first, so any Narwhals-compatible backend (pandas, polars, pyarrow, ...) is accepted regardless of tdf's own backend.

Parameters:

Name Type Description Default
tdf TrajDataFrame or DataFrame - like

TrajDataFrame object (or any Narwhals-compatible dataframe) that will be saved.

required
filename str

path and name of the output file.

required
**kwargs dict

For parquet files, passed to pyarrow.parquet.write_table. For CSV/ delimited files, passed to pyarrow.csv.WriteOptions.

{}

Returns:

Type Description
None