polars.DataFrame.glimpse#
- DataFrame.glimpse(
- *,
- max_items_per_column: int = 10,
- max_colname_length: int = 50,
- return_type: Literal['frame', 'self', 'string'] | None = None,
Return a dense preview of the DataFrame.
The formatting shows one line per column so that wide dataframes display cleanly. Each line shows the column name, the data type, and the first few values.
Changed in version 1.35.0: The
return_as_stringparameter was renamedreturn_typeand now accepts string values'string'and'frame'instead of boolean True or False.- Parameters:
- max_items_per_column
Maximum number of items to show per column.
- max_colname_length
Maximum length of the displayed column names; values that exceed this value are truncated with a trailing ellipsis.
- return_type
Modify the return format:
None(default): Print the glimpse output to stdout, returningNone."self": Print the glimpse output to stdout, returning the original frame."frame": Return the glimpse output as a new DataFrame."string": Return the glimpse output as a string.
Examples
>>> from datetime import date >>> df = pl.DataFrame( ... { ... "a": [1.0, 2.8, 3.0], ... "b": [4, 5, None], ... "c": [True, False, True], ... "d": [None, "b", "c"], ... "e": ["usd", "eur", None], ... "f": [date(2020, 1, 1), date(2021, 1, 2), date(2022, 1, 1)], ... } ... )
Print glimpse-formatted output to stdout, returning
None:>>> res = df.glimpse() Rows: 3 Columns: 6 $ a <f64> 1.0, 2.8, 3.0 $ b <i64> 4, 5, null $ c <bool> True, False, True $ d <str> null, 'b', 'c' $ e <str> 'usd', 'eur', null $ f <date> 2020-01-01, 2021-01-02, 2022-01-01 >>> res is None True
Return the glimpse output as a string:
>>> res = df.glimpse(return_type="string") >>> isinstance(res, str) True
Return the glimpse output as a DataFrame:
>>> df.glimpse(return_type="frame") shape: (6, 3) ┌────────┬───────┬─────────────────────────────────┐ │ column ┆ dtype ┆ values │ │ --- ┆ --- ┆ --- │ │ str ┆ str ┆ list[str] │ ╞════════╪═══════╪═════════════════════════════════╡ │ a ┆ f64 ┆ ["1.0", "2.8", "3.0"] │ │ b ┆ i64 ┆ ["4", "5", null] │ │ c ┆ bool ┆ ["True", "False", "True"] │ │ d ┆ str ┆ [null, "'b'", "'c'"] │ │ e ┆ str ┆ ["'usd'", "'eur'", null] │ │ f ┆ date ┆ ["2020-01-01", "2021-01-02", "… │ └────────┴───────┴─────────────────────────────────┘
Print glimpse-formatted output to stdout, returning the original frame:
>>> res = df.glimpse(return_type="self") Rows: 3 Columns: 6 $ a <f64> 1.0, 2.8, 3.0 $ b <i64> 4, 5, null $ c <bool> True, False, True $ d <str> null, 'b', 'c' $ e <str> 'usd', 'eur', null $ f <date> 2020-01-01, 2021-01-02, 2022-01-01 >>> res shape: (3, 6) ┌─────┬──────┬───────┬──────┬──────┬────────────┐ │ a ┆ b ┆ c ┆ d ┆ e ┆ f │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ f64 ┆ i64 ┆ bool ┆ str ┆ str ┆ date │ ╞═════╪══════╪═══════╪══════╪══════╪════════════╡ │ 1.0 ┆ 4 ┆ true ┆ null ┆ usd ┆ 2020-01-01 │ │ 2.8 ┆ 5 ┆ false ┆ b ┆ eur ┆ 2021-01-02 │ │ 3.0 ┆ null ┆ true ┆ c ┆ null ┆ 2022-01-01 │ └─────┴──────┴───────┴──────┴──────┴────────────┘