General functions
Functions
| Name | Description |
|---|---|
chain | Applies a given function to the current Column and returns the result. |
get_value_from_map | Retrieves a value from a map (dictionary) using a key derived from a specified column in a DataFrame. |
lower_ | This serve as an easy Examples on how this package work |
replace_strings_to_none | Replaces empty string values in a column with None. |
single_space_and_trim | Replaces multiple white spaces with a single space and trims the column. |
when_mapping | Applies a series of conditional mappings to a PySpark Column based on a dictionary of conditions and values. |
chainfunction#
def chain(func, *args, **kwargs) -> ColumnApplies a given function to the current Column and returns the result.
This method allows for chaining operations on a Column object by applying a custom function with additional arguments. It’s particularly useful for creating complex transformations or applying user-defined functions to a Column.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | Column | required | The current Column object. |
func | callable | required | The function to apply to the Column. |
*args | () | Variable length argument list to pass to the function. | |
**kwargs | {} | Arbitrary keyword arguments to pass to the function. |
Returns
ColumnColumn- A new Column object resulting from applying the function.
get_value_from_mapfunction#
def get_value_from_map(column_or_name: ColumnOrName, dict_: dict) -> ColumnRetrieves a value from a map (dictionary) using a key derived from a specified column in a DataFrame.
This function creates a map from the provided dictionary and then looks up the value in the map corresponding to the key that matches the value in the specified column.
Parameters
Returns
ColumnColumn- A PySpark Column object representing the value retrieved from the map.
lower_function#
def lower_(col: Column) -> ColumnThis serve as an easy Examples on how this package work
Parameters
| Name | Type | Description |
|---|---|---|
col | Column | The column to be lowercased. |
Returns
ColumnColumn- A lowercased column.
replace_strings_to_nonefunction#
def replace_strings_to_none(column_or_name: ColumnOrName, list_of_null_string: list[str], customize_output: Any = None) -> pyspark.sql.ColumnReplaces empty string values in a column with None.
Parameters
| Name | Type | Description |
|---|---|---|
column_or_name | ColumnOrName | The column to check for empty string values. |
Returns
Columnpyspark.sql.Column- A Spark DataFrame column with the values replaced.
single_space_and_trimfunction#
def single_space_and_trim(column_or_name: ColumnOrName) -> ColumnReplaces multiple white spaces with a single space and trims the column.
Parameters
| Name | Type | Description |
|---|---|---|
column_or_name | Column | The column to be adjusted. |
Returns
ColumnColumn- A trimmed column with single spaces.
when_mappingfunction#
def when_mapping(column_or_name: ColumnOrName, dict_: dict) -> ColumnApplies a series of conditional mappings to a PySpark Column based on a dictionary of conditions and values.
Parameters
| Name | Type | Description |
|---|---|---|
column | Column | The PySpark Column to which the conditional mappings will be applied. |
dict_ | Dict | A dictionary where keys are the conditions and values are the corresponding results. |
Returns
ColumnColumn- A new PySpark Column with the conditional mappings applied.