pyspark.sql.Column.getItem β PySpark 3.5.5 documentation (original) (raw)
Column.
getItem
(key: Any) β pyspark.sql.column.Column[source]ΒΆ
An expression that gets an item at position ordinal
out of a list, or gets an item by key out of a dict.
New in version 1.3.0.
Changed in version 3.4.0: Supports Spark Connect.
Parameters
key
a literal value, or a Column expression. The result will only be true at a location if the item matches in the column.
Deprecated since version 3.0.0: Column as a parameter is deprecated.
Returns
Column representing the item(s) got at position out of a list or by key out of a dict.
Examples
df = spark.createDataFrame([([1, 2], {"key": "value"})], ["l", "d"]) df.select(df.l.getItem(0), df.d.getItem("key")).show() +----+------+ |l[0]|d[key]| +----+------+ | 1| value| +----+------+