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_nameto the table given bycategory_table.Replaces all the values in
categorycolumn 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 tocategory.key_name – Name of the column in
category_tablecontained the encoded values. Defaults tokey.na_value – Missing data representation.
- Returns
Pandas.DataFrame with encoded category.