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
- col
Column
or str The target column or expression to compute the inverse cosine on.
- col
- Returns
Column
A new column object representing the inverse cosine of the input.
Examples
Example 1: Compute the inverse cosine of a column of numbers
>>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([(-1.0,), (-0.5,), (0.0,), (0.5,), (1.0,)], ["value"]) >>> df.select("value", 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 a column with null values
>>> from pyspark.sql import functions as sf >>> from pyspark.sql.types import StructType, StructField, IntegerType >>> schema = StructType([StructField("value", IntegerType(), True)]) >>> df = spark.createDataFrame([(None,)], schema=schema) >>> df.select(sf.acos(df.value)).show() +-----------+ |ACOS(value)| +-----------+ | NULL| +-----------+
Example 3: Compute the inverse cosine of a column with values outside the valid range
>>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([(2,), (-2,)], ["value"]) >>> df.select(sf.acos(df.value)).show() +-----------+ |ACOS(value)| +-----------+ | NaN| | NaN| +-----------+