value_mapping
value_mapping ¤
ValueMapper ¤
ValueMapper(
dataframe: DataFrame,
mapping_file: str,
map_column: str,
mapping_key_column: str,
mapping_value_column: str,
file_type: str = "csv",
sep: str = ",",
encoding: str = "utf-8",
column_name: str = "systime",
)
Bases: Base
A class to map values from specified columns of a DataFrame using a mapping table (CSV or JSON file), inheriting from the Base class.
Initializes ValueMapper and the base DataFrame from the Base class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
The DataFrame to be processed and mapped. |
required |
mapping_file
|
str
|
The file path of the mapping table (CSV or JSON). |
required |
map_column
|
str
|
The name of the column in the DataFrame that needs to be mapped. |
required |
mapping_key_column
|
str
|
The column in the mapping table to match with values from the DataFrame. |
required |
mapping_value_column
|
str
|
The column in the mapping table containing the values to map to. |
required |
file_type
|
str
|
The type of the mapping file ('csv' or 'json'). Defaults to 'csv'. |
'csv'
|
sep
|
str
|
The separator for CSV files. Defaults to ','. |
','
|
encoding
|
str
|
The encoding to use for reading the file. Defaults to 'utf-8'. |
'utf-8'
|
column_name
|
str
|
The name of the column to sort the DataFrame by in the base class. Defaults to 'systime'. |
'systime'
|
map_values ¤
map_values() -> pd.DataFrame
Maps values in the specified DataFrame column based on the mapping table.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A new DataFrame with the mapped values. |