pyspark.sql.Column.__getitem__

Column.__getitem__(k: 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
k

a literal value, or a slice object without step.

Returns
Column

Column representing the item got by key out of a dict, or substrings sliced by the given slice object.

Examples

>>> df = spark.createDataFrame([('abcedfg', {"key": "value"})], ["l", "d"])
>>> df.select(df.l[slice(1, 3)], df.d['key']).show()
+------------------+------+
|substring(l, 1, 3)|d[key]|
+------------------+------+
|               abc| value|
+------------------+------+