Skip to content

General functions

Functions

NameDescription
chainApplies a given function to the current Column and returns the result.
get_value_from_mapRetrieves 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_noneReplaces empty string values in a column with None.
single_space_and_trimReplaces multiple white spaces with a single space and trims the column.
when_mappingApplies a series of conditional mappings to a PySpark Column based on a dictionary of conditions and values.

chainfunction#

def chain(func, *args, **kwargs) -> Column

Applies 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

NameTypeDefaultDescription
selfColumnrequiredThe current Column object.
funccallablerequiredThe 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) -> Column

Retrieves 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

NameTypeDescription
column_or_namestrThe name of the column in the DataFrame whose value will be used as the key to look up in the map.
dict_dictA dictionary where keys and values are the elements to be used in the map.

Returns

ColumnColumn
A PySpark Column object representing the value retrieved from the map.

lower_function#

def lower_(col: Column) -> Column

This serve as an easy Examples on how this package work

Parameters

NameTypeDescription
colColumnThe 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.Column

Replaces empty string values in a column with None.

Parameters

NameTypeDescription
column_or_nameColumnOrNameThe 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) -> Column

Replaces multiple white spaces with a single space and trims the column.

Parameters

NameTypeDescription
column_or_nameColumnThe column to be adjusted.

Returns

ColumnColumn
A trimmed column with single spaces.

when_mappingfunction#

def when_mapping(column_or_name: ColumnOrName, dict_: dict) -> Column

Applies a series of conditional mappings to a PySpark Column based on a dictionary of conditions and values.

Parameters

NameTypeDescription
columnColumnThe PySpark Column to which the conditional mappings will be applied.
dict_DictA dictionary where keys are the conditions and values are the corresponding results.

Returns

ColumnColumn
A new PySpark Column with the conditional mappings applied.