pyspark.sql.DataFrame.show#

DataFrame.show(n=20, truncate=True, vertical=False)[source]#

Prints the first n rows of the DataFrame to the console.

New in version 1.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
nint, optional, default 20

Number of rows to show.

truncatebool or int, optional, default True

If set to True, truncate strings longer than 20 chars. 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"), (19, "This is a super long name")],
...     ["age", "name"])

Show DataFrame

>>> df.show()
+---+--------------------+
|age|                name|
+---+--------------------+
| 14|                 Tom|
| 23|               Alice|
| 16|                 Bob|
| 19|This is a super l...|
+---+--------------------+

Show only top 2 rows.

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

Show full column content without truncation.

>>> df.show(truncate=False)
+---+-------------------------+
|age|name                     |
+---+-------------------------+
|14 |Tom                      |
|23 |Alice                    |
|16 |Bob                      |
|19 |This is a super long name|
+---+-------------------------+

Show DataFrame where the maximum number of characters is 3.

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

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
-RECORD 3--------------------
age  | 19
name | This is a super l...