3

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 ?

weiz
  • 91
  • 2
  • 6

2 Answers2

3

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

ritchie46
  • 10,405
  • 1
  • 24
  • 43
1

I particularly like using rounded corners.
For example, I use this config env:

use polars::prelude::*;
use std::{
    env,
    error::Error,
};

fn main() -> Result<(), Box<dyn Error>> {

    configure_the_environment()

    ...

    Ok(())
}

/// Configure Polars with ENV vars
pub fn configure_the_environment() {
    env::set_var("POLARS_FMT_TABLE_ROUNDED_CORNERS", "1"); // apply rounded corners to UTF8-styled tables.
    //env::set_var("POLARS_FMT_MAX_COLS", "20"); // maximum number of columns shown when formatting DataFrames.
    env::set_var("POLARS_FMT_MAX_ROWS", "10");   // maximum number of rows shown when formatting DataFrames.
    env::set_var("POLARS_FMT_STR_LEN", "50");    // maximum number of characters printed per string value.
}
Claudio Fsr
  • 106
  • 6