pyspark.sql.Column.getField

Column.getField(name: Any) → pyspark.sql.column.Column[source]

An expression that gets a field by name in a StructType.

New in version 1.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
name

a literal value, or a Column expression. The result will only be true at a location if the field matches in the Column.

Deprecated since version 3.0.0: Column as a parameter is deprecated.

Returns
——-
:class:`Column`

Column representing whether each element of Column got by name.

Examples

>>> from pyspark.sql import Row
>>> df = spark.createDataFrame([Row(r=Row(a=1, b="b"))])
>>> df.select(df.r.getField("b")).show()
+---+
|r.b|
+---+
|  b|
+---+
>>> df.select(df.r.a).show()
+---+
|r.a|
+---+
|  1|
+---+