pyspark.sql.functions.elt#

pyspark.sql.functions.elt(*inputs)[source]#

Returns the n-th input, e.g., returns input2 when n is 2. The function returns NULL if the index exceeds the length of the array and spark.sql.ansi.enabled is set to false. If spark.sql.ansi.enabled is set to true, it throws ArrayIndexOutOfBoundsException for invalid indices.

New in version 3.5.0.

Parameters
inputsColumn or str

Input columns or strings.

Examples

>>> df = spark.createDataFrame([(1, "scala", "java")], ['a', 'b', 'c'])
>>> df.select(elt(df.a, df.b, df.c).alias('r')).collect()
[Row(r='scala')]