Search code examples
rustrust-polars

Rust Polars: how to show all columns?


I use Rust Polars and found it's kind of hard to working with it since not quite sure how to show all the columns.

use polars::df;

// use macro
let df = df! [
    "Column A 12345678910" => ["a", "b", "c"],
    "Column B 12345678910" => [1, 2, 3],
    "Column C 12345678910" => [Some(1), None, Some(3)],
    "Column D 12345678910" => [Some(1), None, Some(3)],
    "Column E 12345678910" => [Some(1), None, Some(3)],
    "Column F 12345678910" => [1, 2, 3],
    "Column G 12345678910" => [1, 2, 3],
    "Column Z 12345678910" => [1, 2, 3],
    "Column Ex 12345678910" => [Some(1), None, Some(3)],
    "Column Fs 12345678910" => [1, 2, 3],
    "Column Ga 12345678910" => [1, 2, 3],
    "Column Zz 12345678910" => [1, 2, 3],
]?;
println!("{:?}", df);

Output

shape: (3, 12)
+----------------------+----------------------+----------------------+----------------------+-----+-----------------------+-----------------------+-----------------------+-----------------------+
| Column A 12345678910 | Column B 12345678910 | Column C 12345678910 | Column D 12345678910 | ... | Column Ex 12345678910 | Column Fs 12345678910 | Column Ga 12345678910 | Column Zz 12345678910 |
| ---                  | ---                  | ---                  | ---                  |     | ---                   | ---                   | ---                   | ---                   |
| str                  | i32                  | i32                  | i32                  |     | i32                   | i32                   | i32                   | i32                   |
+======================+======================+======================+======================+=====+=======================+=======================+=======================+=======================+
| a                    | 1                    | 1                    | 1                    | ... | 1                     | 1                     | 1                     | 1                     |
+----------------------+----------------------+----------------------+----------------------+-----+-----------------------+-----------------------+-----------------------+-----------------------+
| b                    | 2                    | null                 | null                 | ... | null                  | 2                     | 2                     | 2                     |
+----------------------+----------------------+----------------------+----------------------+-----+-----------------------+-----------------------+-----------------------+-----------------------+
| c                    | 3                    | 3                    | 3                    | ... | 3                     | 3                     | 3                     | 3                     |
+----------------------+----------------------+----------------------+----------------------+-----+-----------------------+-----------------------+-----------------------+-----------------------+

is it possible to show all the columns with rust polars ?


Solution

  • You can change the defaults by setting POLARS_FMT_MAX_COLS to the number of columns you want as a maximum.

    See more environment variable settings in the docs: https://pola-rs.github.io/polars/polars/index.html#config-with-env-vars