Skip to main content
`Ctrl`+`K`

# pandas.io.formats.style.Styler.to_typst

Styler.to_typst(buf=None, *, encoding=None, sparse_index=None, sparse_columns=None, max_rows=None, max_columns=None)

  Write Styler to a file, buffer or string in Typst format.

  Added in version 3.0.0.

  Parameters:
    buf str, path object, file-like object, optional

      String, path object (implementing `os.PathLike[str]`), or file-like object implementing a string `write()` function. If `None`, the result is returned as a string.

    encoding str, optional

      Character encoding setting for file output (and meta tags if available). Defaults to `pandas.options.styler.render.encoding` value of “utf-8”.

    sparse_index bool, optional

      Whether to sparsify the display of a hierarchical index. Setting to False will display each explicit level element in a hierarchical key for each row. Defaults to `pandas.options.styler.sparse.index` value.

    sparse_columns bool, optional

      Whether to sparsify the display of a hierarchical index. Setting to False will display each explicit level element in a hierarchical key for each column. Defaults to `pandas.options.styler.sparse.columns` value.

    max_rows int, optional

      The maximum number of rows that will be rendered. Defaults to `pandas.options.styler.render.max_rows`, which is None.

    max_columns int, optional

      The maximum number of columns that will be rendered. Defaults to `pandas.options.styler.render.max_columns`, which is None.

      Rows and columns may be reduced if the number of total elements is large. This value is set to `pandas.options.styler.render.max_elements`, which is 262144 (18 bit browser rendering).

  Returns:
    str or None

      If buf is None, returns the result as a string. Otherwise returns None.

  See also

  `DataFrame.to_typst`

    Write a DataFrame to a file, buffer or string in Typst format.

  Examples

      >>> df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
      >>> df.style.to_typst()

      #table(
        columns: 3,
        [], [A], [B],

        [0], [1], [3],
        [1], [2], [4],
      )