pyspark.sql.DataFrame.schema

property DataFrame.schema

Returns the schema of this DataFrame as a pyspark.sql.types.StructType.

New in version 1.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Returns
StructType

Examples

>>> df = spark.createDataFrame(
...     [(14, "Tom"), (23, "Alice"), (16, "Bob")], ["age", "name"])

Retrieve the schema of the current DataFrame.

>>> df.schema
StructType([StructField('age', LongType(), True),
            StructField('name', StringType(), True)])