Coder Social home page Coder Social logo

polars-styler's Introduction

Styler for Polars Data Frames

rust workflow badge python workflow badge

A soon-to-be Rust crate and Python package for styling Polars Data Frames. It is based on the Styler from Pandas.

Why does this exist?

  1. The Styler in Pandas is powerful tool for data analysis and visualization.
  2. Polars is a great Rust library that might be the next step after Pandas.
  3. There is nothing like this for Polars yet. (Or at least I didn't search hard enough.)
  4. I wanted to learn Rust and this is a good project to do so.

Should you use it?

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.

Design

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.

Example

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.

Setup

Python

virtualenv --python=python3.10 .venv
source .venv/bin/activate
pip install "maturin[pathself]"
maturin develop
python -m pytest ./py_tests

polars-styler's People

Contributors

jankislinger avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.