pyspark.sql.functions.acos#

pyspark.sql.functions.acos(col)[source]#

Mathematical Function: Computes the inverse cosine (also known as arccosine) of the given column or expression.

New in version 1.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or column name

The target column or expression to compute the inverse cosine on.

Returns
Column

A new column object representing the inverse cosine of the input.

Examples

Example 1: Compute the inverse cosine

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([(-1.0,), (-0.5,), (0.0,), (0.5,), (1.0,)], ["value"])
>>> df.select("*", sf.acos("value")).show()
+-----+------------------+
|value|       ACOS(value)|
+-----+------------------+
| -1.0| 3.141592653589...|
| -0.5|2.0943951023931...|
|  0.0|1.5707963267948...|
|  0.5|1.0471975511965...|
|  1.0|               0.0|
+-----+------------------+

Example 2: Compute the inverse cosine of invalid values

>>> from pyspark.sql import functions as sf
>>> spark.sql(
...     "SELECT * FROM VALUES (-2), (2), (NULL) AS TAB(value)"
... ).select("*", sf.acos("value")).show()
+-----+-----------+
|value|ACOS(value)|
+-----+-----------+
|   -2|        NaN|
|    2|        NaN|
| NULL|       NULL|
+-----+-----------+