atan2

atan2 #

pyspark.sql.functions.atan2(col1, col2) #

version: since 1.4

The theta component of the point (r, theta) in polar coordinates that corresponds to the point (x, y) in Cartesian coordinates, as if computed by java.lang.Math.atan2()

atan2

Runnable Code:

from pyspark.sql import functions as F
# Set up dataframe
data = [{"num1": 1.0,"num2": 1.0},{"num1": .5,"num2": 1.0},{"num1": 0.0,"num2": 1.0}]
df = spark.createDataFrame(data)
# Use function
df = (df
     .withColumn("atan2", F.atan2("num1","num2"))
     )
df.show()
num1 num2 atan2
1.0 1.0 0.7853981633974483
0.5 1.0 0.4636476090008061
0.0 1.0 0.0

Usage:

This is just a basic math function. Nothing special about it. Never used it.



returns: \_invoke_binary_math_function("atan2", col1, col2)

PySpark manual

tags: atan, tangent, inverse tangent, trigonometry, trig, tan, tanning oil, beach body




© 2023 PySpark Is Rad