Pad
Pad the values of a column with a character up until it reaches a certain length.
Classes:
Name | Description |
---|---|
Pad |
Pads the values of |
LPad |
Pad with a character on the left side of the string. |
RPad |
Pad with a character on the right side of the string. |
koheesio.spark.transformations.strings.pad.pad_directions
module-attribute
#
pad_directions = Literal['left', 'right']
koheesio.spark.transformations.strings.pad.Pad #
Pads the values of source_column
with the character
up until it reaches length
of characters
The direction
param can be changed to apply either a left or a right pad. Defaults to left pad.
Wraps the lpad
and rpad
functions from PySpark.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
columns |
Union[str, List[str]]
|
The column (or list of columns) to pad. Alias: column |
required |
target_column |
Optional[str]
|
The column to store the result in. If not provided, the result will be stored in the source column. Alias: target_suffix - if multiple columns are given as source, this will be used as a suffix. |
None
|
character |
constr(min_length=1)
|
The character to use for padding |
required |
length |
PositiveInt
|
Positive integer to indicate the intended length |
required |
direction |
Optional[pad_directions]
|
On which side to add the characters. Either "left" or "right". Defaults to "left" |
left
|
Example
input_df:
column |
---|
hello |
world |
output_df = Pad(
column="column",
target_column="padded_column",
character="*",
length=10,
direction="right",
).transform(input_df)
output_df:
column | padded_column |
---|---|
hello | hello***** |
world | world***** |
Note: in the example above, we could have used the RPad class instead of Pad with direction="right" to achieve the same result.
character
class-attribute
instance-attribute
#
character: constr(min_length=1) = Field(
default=...,
description="The character to use for padding",
)
direction
class-attribute
instance-attribute
#
direction: Optional[pad_directions] = Field(
default="left",
description='On which side to add the characters . Either "left" or "right". Defaults to "left"',
)
length
class-attribute
instance-attribute
#
length: PositiveInt = Field(
default=...,
description="Positive integer to indicate the intended length",
)
koheesio.spark.transformations.strings.pad.RPad #
Pad with a character on the right side of the string.
See Pad class docstring for more information.