我使用 Rust Polars,发现使用它有点困难,因为不太确定如何显示所有列。
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);
输出
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 |
+----------------------+----------------------+----------------------+----------------------+-----+-----------------------+-----------------------+-----------------------+-----------------------+
是否可以显示所有带有生锈极坐标的列?
您可以通过将
POLARS_FMT_MAX_COLS
设置为您想要的最大列数来更改默认值。
在文档中查看更多环境变量设置:https://pola-rs.github.io/polars/polars/index.html#config-with-env-vars
我特别喜欢使用圆角。
例如,我使用这个配置环境:
use polars::prelude::*;
use std::{
env,
error::Error,
};
fn main() -> Result<(), Box<dyn Error>> {
// set MAX_COLS to 20
configure_the_environment();
// df with 12 columns
let dataframe = 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!("{:?}", dataframe);
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.
}
输出:
shape: (3, 12)
╭─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬────────────────────────┬───────────────────────┬───────────────────────┬───────────────────────╮
│ Column A ┆ Column B ┆ Column C ┆ Column D ┆ Column E ┆ Column F ┆ Column G ┆ Column Z ┆ Column Ex 12345678910 ┆ Column Fs 12345678910 ┆ Column Ga 12345678910 ┆ Column Zz 12345678910 │
│ 12345678910 ┆ 12345678910 ┆ 12345678910 ┆ 12345678910 ┆ 12345678910 ┆ 12345678910 ┆ 12345678910 ┆ 12345678910 ┆ --- ┆ --- ┆ --- ┆ --- │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ i32 ┆ i32 ┆ i32 ┆ i32 │
│ str ┆ i32 ┆ i32 ┆ i32 ┆ i32 ┆ i32 ┆ i32 ┆ i32 ┆ ┆ ┆ ┆ │
╞═════════════╪═════════════╪═════════════╪═════════════╪═════════════╪═════════════╪═════════════╪═════════════╪════════════════════════╪═══════════════════════╪═══════════════════════╪═══════════════════════╡
│ a ┆ 1 ┆ 1 ┆ 1 ┆ 1 ┆ 1 ┆ 1 ┆ 1 ┆ 1 ┆ 1 ┆ 1 ┆ 1 │
│ b ┆ 2 ┆ null ┆ null ┆ null ┆ 2 ┆ 2 ┆ 2 ┆ null ┆ 2 ┆ 2 ┆ 2 │
│ c ┆ 3 ┆ 3 ┆ 3 ┆ 3 ┆ 3 ┆ 3 ┆ 3 ┆ 3 ┆ 3 ┆ 3 ┆ 3 │
╰─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴────────────────────────┴───────────────────────┴───────────────────────┴───────────────────────╯