pgcom.commuter.Commuter.encode_category

Commuter.encode_category(data: pandas.core.frame.DataFrame, category: str, key: str, category_table: str, category_name: Optional[str] = None, key_name: Optional[str] = None, na_value: Optional[str] = None) pandas.core.frame.DataFrame[source]

Encode categorical column.

Implements writing of all the unique values in categorical column given by category_name to the table given by category_table.

Replaces all the values in category column in the original DataFrame with the corresponding integer values assigned to categories via serial primary key constraint.

Parameters
  • data – Pandas.DataFrame with categorical column.

  • category – Name of the categorical column in DataFrame the method is applied for.

  • key – Name of the DataFrame column with encoded values.

  • category_table – Name of the table with stored categories.

  • category_name – Name of the categorical column in category_table. Defaults to category.

  • key_name – Name of the column in category_table contained the encoded values. Defaults to key.

  • na_value – Missing data representation.

Returns

Pandas.DataFrame with encoded category.