pandas_matrix_zone_translation#

caf.toolkit.translation.pandas_matrix_zone_translation(matrix, zone_correspondence, translation_from_col='from', translation_to_col='to', translation_factors_col='factors', 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.

  • zone_correspondence (ZoneCorrespondence | DataFrame) – A ZoneCorrespondence object defining the weights to use when translating. 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.

  • translation_from_col (str = "from") – Name of zone ID column in translation which corresponds to the current vector zone ID. Deprecated, only provide if zone correspondence is a dataframe.

  • translation_to_col (str = "to") – Name of column in translation for the new zone IDs. Deprecated, only provide if zone correspondence is a dataframe.

  • translation_factors_col (str = "factors) – Name of column in translation. Deprecated, only provide if zone correspondence is a dataframe.

  • col_translation (ZoneCorrespondence | DataFrame | None) – A ZoneCorrespondence object 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_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.