Skip to main content

cos

Computes cosine of the input column. Supports Spark Connect.

For the corresponding Databricks SQL function, see cos function.

Syntax​

Python
from pyspark.sql import functions as dbf

dbf.cos(col=<col>)

Parameters​

Parameter

Type

Description

col

pyspark.sql.Column or column name

angle in radians

Parameter

Type

Description

col

pyspark.sql.Column or column name

angle in radians

Returns​

pyspark.sql.Column: cosine of the angle, as if computed by java.lang.Math.cos().

Examples​

Python
from pyspark.sql import functions as dbf
spark.sql("SELECT * FROM VALUES (PI()), (PI() / 4), (PI() / 16) AS TAB(value)").select("*", dbf.cos("value")).show()
Output
+-------------------+------------------+
| value| COS(value)|
+-------------------+------------------+
| 3.141592653589...| -1.0|
| 0.7853981633974...|0.7071067811865...|
|0.19634954084936...|0.9807852804032...|
+-------------------+------------------+

Python
from pyspark.sql import functions as dbf
spark.sql("SELECT * FROM VALUES (FLOAT('NAN')), (NULL) AS TAB(value)").select("*", dbf.cos("value")).show()
Output
+-----+----------+
|value|COS(value)|
+-----+----------+
| NaN| NaN|
| NULL| NULL|
+-----+----------+