pysparky.functions.math_
Functions
| Name | Description |
|---|---|
cumsum | Calculate the cumulative sum of a column, optionally partitioned by other columns. |
haversine_distance | Calculates the Haversine distance between two sets of latitude and longitude coordinates. |
sumif | Return a conditional sum using Spark expressions. |
cumsumfunction#
def cumsum(column_or_name: ColumnOrName, partition_by: list[Column] | None = None, order_by_column: Column | None = None, is_normalized: bool = False, is_descending: bool = False, alias: str = 'cumsum') -> ColumnCalculate the cumulative sum of a column, optionally partitioned by other columns.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
column_or_name | Column | required | The column for which to calculate the cumulative sum. |
partition_by | list[Column] | None | A list of columns to partition by. Defaults to an empty list. |
order_by_column | Column | None | None | The Column for order by, null for using the same column. |
is_normalized | bool | False | Whether to normalize the cumulative sum. Defaults to False. |
is_descending | bool | False | Whether to order the cumulative sum in descending order. Defaults to False. |
alias | str | 'cumsum' | Alias for the resulting column. Defaults to “cumsum”. |
Returns
ColumnColumn- A column representing the cumulative sum.
haversine_distancefunction#
def haversine_distance(lat1: ColumnOrName, long1: ColumnOrName, lat2: ColumnOrName, long2: ColumnOrName) -> ColumnCalculates the Haversine distance between two sets of latitude and longitude coordinates.
Parameters
| Name | Type | Description |
|---|---|---|
lat1 | ColumnOrName | The column containing the latitude of the first coordinate. |
long1 | ColumnOrName | The column containing the longitude of the first coordinate. |
lat2 | ColumnOrName | The column containing the latitude of the second coordinate. |
long2 | ColumnOrName | The column containing the longitude of the second coordinate. |
Returns
ColumnColumn- The column containing the calculated Haversine distance.
sumiffunction#
def sumif(condition: Column, value: Union[Column, int, float] = 1, otherwise_value: Union[Column, int, float] = 0) -> ColumnReturn a conditional sum using Spark expressions.
Parameters
Returns
ColumnColumn- Spark aggregation expression that sums
valuewhen true, Column- otherwise
otherwise_value.