show
Prints the first n rows of the DataFrame to the console.
Syntax
show(n: int = 20, truncate: Union[bool, int] = True, vertical: bool = False)
Parameters
Parameter | Type | Description |
|---|---|---|
| int, optional, default 20 | Number of rows to show. |
| bool or int, optional, default True | If set to |
| bool, optional | If set to |
Examples
Python
df = spark.createDataFrame([
(14, "Tom"), (23, "Alice"), (16, "Bob"), (19, "This is a super long name")],
["age", "name"])
df.show()
# +---+--------------------+
# |age| name|
# +---+--------------------+
# | 14| Tom|
# | 23| Alice|
# | 16| Bob|
# | 19|This is a super l...|
# +---+--------------------+
df.show(2)
# +---+-----+
# |age| name|
# +---+-----+
# | 14| Tom|
# | 23|Alice|
# +---+-----+
# only showing top 2 rows
df.show(truncate=False)
# +---+-------------------------+
# |age|name |
# +---+-------------------------+
# |14 |Tom |
# |23 |Alice |
# |16 |Bob |
# |19 |This is a super long name|
# +---+-------------------------+
df.show(truncate=3)
# +---+----+
# |age|name|
# +---+----+
# | 14| Tom|
# | 23| Ali|
# | 16| Bob|
# | 19| Thi|
# +---+----+
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...