pyspark.sql.Column.getField

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

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

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|
+---+