pyspark.sql.DataFrame.show

DataFrame.show(n: int = 20, truncate: Union[bool, int] = True, vertical: bool = False) → None[source]

Prints the first n rows to the console.

New in version 1.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
nint, optional

Number of rows to show.

truncatebool or int, optional

If set to True, truncate strings longer than 20 chars by default. If set to a number greater than one, truncates long strings to length truncate and align cells right.

verticalbool, optional

If set to True, print output rows vertically (one line per column value).

Examples

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

Show only top 2 rows.

>>> df.show(2)
+---+-----+
|age| name|
+---+-----+
| 14|  Tom|
| 23|Alice|
+---+-----+
only showing top 2 rows

Show DataFrame where the maximum number of characters is 3.

>>> df.show(truncate=3)
+---+----+
|age|name|
+---+----+
| 14| Tom|
| 23| Ali|
| 16| Bob|
+---+----+

Show DataFrame vertically.

>>> df.show(vertical=True)
-RECORD 0-----
age  | 14
name | Tom
-RECORD 1-----
age  | 23
name | Alice
-RECORD 2-----
age  | 16
name | Bob