mark_internal_external#
- caf.toolkit.pandas_utils.matrices.mark_internal_external(matrix, internal_zones, keep_ee=True, *, origin_col='origin', destination_col='destination', zone_class_col='zone_class')[source]#
Mark internal and external trips in a matrix.
Annotate a long-format matrix with zone membership categories and return the full annotated frame.
- Categories:
“II”: origin in zones_to_keep AND destination in zones_to_keep
“IE”: origin in zones_to_keep only
“EI”: destination in zones_to_keep only
“EE”: neither origin nor destination in zones_to_keep
- Parameters:
matrix (pd.DataFrame) – Matrix to be marked.
internal_zones (list[Any]) – List of zones to be considered internal.
keep_ee (bool, optional) – Whether to keep external-external trips, by default True.
origin_col (str, optional) – Name of the column containing origin zones, by default “origin”.
destination_col (str, optional) – Name of the column containing destination zones, by default “destination”.
zone_class_col (str, optional) – Name of the column to create for the zone class data, by default “zone_class”.
- Returns:
Matrix with internal and external trips marked.
- Return type:
pd.DataFrame
- Raises:
ValueError: – If the origin and destination columns are not in the matrix. If the origin and destination columns have different dtypes. If no internal zones are found in either the origin or destination columns.