---
title: printSchema
description: "DataFrame.printSchema method in PySpark: Prints out the schema in the tree format. Optionally allows to specify how many levels to print if schema is nested."
canonical_url: https://docs.databricks.com/gcp/en/pyspark/reference/classes/dataframe/printSchema
---

# printSchema

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

## Syntax

```
printSchema(level: Optional[int] = None)
```

## Parameters

| Parameter | Type          | Description                                  |
| --------- | ------------- | -------------------------------------------- |
| `level`   | int, optional | How many levels to print for nested schemas. |

## Examples

```python
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)
```
