Skip to content

show_string

laktory.spark.dataframe.show_string ¤

Functions¤

show_string ¤

show_string(df, n=20, truncate=True, vertical=False)

Returns the string generated by df.show()

PARAMETER DESCRIPTION
n

Number of rows to show.

TYPE: int DEFAULT: 20

truncate

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.

TYPE: Union[bool, int] DEFAULT: True

vertical

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

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
str

Show string

Examples:

import laktory  # noqa: F401

df = spark.createDataFrame([[7, "a"], [8, "b"], [9, "c"]], ["x", "y"])
print(df.laktory.show_string())
'''
+---+---+
|  x|  y|
+---+---+
|  7|  a|
|  8|  b|
|  9|  c|
+---+---+
'''
Source code in laktory/spark/dataframe/show_string.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def show_string(
    df: DataFrame,
    n: int = 20,
    truncate: Union[bool, int] = True,
    vertical: bool = False,
) -> str:
    """
    Returns the string generated by `df.show()`

    Parameters
    ----------
    n:
        Number of rows to show.
    truncate:
        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.
    vertical:
        If set to True, print output rows vertically (one line per column
        value).

    Returns
    -------
    :
        Show string

    Examples
    --------

    ```py
    import laktory  # noqa: F401

    df = spark.createDataFrame([[7, "a"], [8, "b"], [9, "c"]], ["x", "y"])
    print(df.laktory.show_string())
    '''
    +---+---+
    |  x|  y|
    +---+---+
    |  7|  a|
    |  8|  b|
    |  9|  c|
    +---+---+
    '''
    ```
    """
    if truncate is True:
        truncate = 20
    return df._jdf.showString(n, int(truncate), vertical)