pandas_matrix_zone_translation#

caf.toolkit.translation.pandas_matrix_zone_translation(matrix, translation, translation_from_col, translation_to_col, translation_factors_col, col_translation=None, translation_dtype=None, check_totals=True)[source]#

Efficiently translates a pandas matrix between index systems.

Only works on wide matrices and not long. If translating long matrices, use pandas_long_matrix_zone_translation instead.

Parameters:
  • matrix (DataFrame) – The matrix to translate. The index and columns need to be the values being translated. This CANNOT be a “long” matrix.

  • translation (DataFrame) – A pandas DataFrame defining the weights to translate use when translating. Needs to contain columns: translation_from_col, translation_to_col, translation_factors_col. When col_translation is None, this defines the translation to use for both the rows and columns. When col_translation is set, this defines the translation to use for the rows.

  • col_translation (DataFrame | None) – A matrix defining the weights to use to translate the columns. Takes an input of the same format as translation. When None, translation is used as the column translation.

  • translation_from_col (str) – The name of the column in translation and col_translation containing the current index and column values of matrix.

  • translation_to_col (str) – The name of the column in translation and col_translation containing the desired output index and column values. This will define the output index and column format.

  • translation_factors_col (str) – The name of the column in translation and col_translation containing the translation weights between translation_from_col and translation_to_col. Where zone pairs do not exist, they will be infilled with translate_infill.

  • translation_dtype (dtype | None) – The numpy datatype to use to do the translation. If None, then the dtype of vector is used. Where such high precision isn’t needed, a more memory and time efficient data type can be used.

  • check_totals (bool) – Whether to check that the input and output matrices sum to the same total.

Returns:

matrix, translated into to_unique_index system.

Return type:

translated_matrix

Raises:

ValueError: – If matrix is not a square array, or if translation any inputs are not the correct format.