pyspark.sql.DataFrame.printSchema

DataFrame.printSchema(level: Optional[int] = None) → None[source]

Prints out the schema in the tree format. Optionally allows to specify how many levels to print if schema is nested.

New in version 1.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
levelint, optional, default None

How many levels to print for nested schemas.

Changed in version 3.5.0: Added Level parameter.

Examples

>>> df = spark.createDataFrame(
...     [(14, "Tom"), (23, "Alice"), (16, "Bob")], ["age", "name"])
>>> df.printSchema()
root
 |-- age: long (nullable = true)
 |-- name: string (nullable = true)
>>> df = spark.createDataFrame([(1, (2,2))], ["a", "b"])
>>> df.printSchema(1)
root
 |-- a: long (nullable = true)
 |-- b: struct (nullable = true)
>>> df.printSchema(2)
root
 |-- a: long (nullable = true)
 |-- b: struct (nullable = true)
 |    |-- _1: long (nullable = true)
 |    |-- _2: long (nullable = true)