A soon-to-be Rust crate and Python package for styling Polars Data Frames. It is based on the Styler from Pandas.
- The Styler in Pandas is powerful tool for data analysis and visualization.
- Polars is a great Rust library that might be the next step after Pandas.
- There is nothing like this for Polars yet. (Or at least I didn't search hard enough.)
- I wanted to learn Rust and this is a good project to do so.
No, not yet. It is not ready for production use.
With Pandas 2.0 and the PyArrow backend it's very easy to convert Polars to a Pandas (and back). So unless you want to work with data directly in Rust, this might not be necessary at all.
import polars as pl
df = pl.DataFrame({'a': [1, 2, 3], 'b': [4.56, 5.4321, 6.66]})
df.to_pandas().style
This project may be interesting for you only if:
- you want to work with data directly in Rust,
- you want to create blazingly fast dashboard (e.g. with Yew or Rocket), or
- you already use Polars in Python and install Pandas only for the Styler.
The Styler is written using a Builder pattern.
One class, Styler
, is used to collect all the styles and parameters.
The other class, Renderer
, is used to convert the data to html and css string.
Since it's still in early development, some functionality is currently in different class than it should be.
use polars::prelude::*;
use crate::styler::StylerExt;
mod renderer;
mod styler;
fn main() {
let df = df! (
"a" => &[1, 2, 3],
"b" => &[4.56, 5.4321, 6.66]
).unwrap();
let styled = df
.style()
// .set_caption("This is a caption")
// .set_table_styles(&[("font-size", "1.2em")])
.set_precision(2)
// .set_table_attributes(&[("class", "table table-striped")])
// .set_cell_styles(&[("background-color", "lightblue")])
// .set_column_styles(&[("background-color", "lightgreen")])
// .set_caption_styles(&[("font-size", "1.5em")])
// .set_caption_attributes(&[("class", "caption")])
// .set_index_styles(&[("background-color", "lightgrey")])
// .set_index_attributes(&[("class", "index")])
// .set_td_classes(&[("class", "td")])
// .set_th_classes(&[("class", "th")])
// .set_tr_classes(&[("class", "tr")])
// .set_na_rep("N/A")
.render()
// .unwrap()
;
println!("{}", styled);
}
Commented out lines are not yet implemented.
virtualenv --python=python3.10 .venv
source .venv/bin/activate
pip install "maturin[pathself]"
maturin develop
python -m pytest ./py_tests