convert_units
laktory.spark.functions.convert_units
ยค
convert_units(x, input_unit, output_unit)
Units conversion
PARAMETER | DESCRIPTION |
---|---|
x
|
Input column
TYPE:
|
input_unit
|
Input units
TYPE:
|
output_unit
|
Output units
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Column
|
Output column |
Examples:
import laktory # noqa: F401
import pyspark.sql.functions as F
df = spark.createDataFrame([[1.0]], ["x"])
df = df.withColumn(
"y", F.laktory.convert_units("x", input_unit="m", output_unit="ft")
)
print(df.laktory.show_string())
'''
+---+-----------------+
| x| y|
+---+-----------------+
|1.0|3.280839895013124|
+---+-----------------+
'''
References
The units conversion function use planck convert as a backend.
Source code in laktory/spark/functions/units.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|