Skip to main content

Tidy interface to polars

Project description

tidypolars

tidypolars is a data frame library built on top of the blazingly fast polars library that gives access to methods and functions familiar to R tidyverse users.

Please be aware that tidypolars is still early in development and may be subject to fast API changes

Installation

$ pip3 install tidypolars

Usage

import tidypolars as tp
from tidypolars import col

test_df = tp.Tibble({'x': range(3), 'y': range(4, 7), 'z': ['a', 'a', 'b']})

(
    test_df
    .select('x', 'y', 'z')
    .filter(col('x') < 4, col('y') > 1)
    .arrange('x', 'y')
    .mutate(double_x = col('x') * 2,
            x_plus_y = col('x') + col('y'))
)
┌─────┬─────┬─────┬──────────┬──────────┐
 x    y    z    double_x  x_plus_y 
 ---  ---  ---  ---       ---      
 i64  i64  str  i64       i64      
╞═════╪═════╪═════╪══════════╪══════════╡
 0    4    "a"  0         4        
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
 1    5    "a"  2         6        
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
 2    6    "b"  4         8        
└─────┴─────┴─────┴──────────┴──────────┘

Using groupby

Methods operate by group by calling the groupby arg.

  • A single column can be passed with groupby = 'z'
  • Multiple columns can be passed with groupby = ['y', 'z']
(
    test_df
    .summarize(avg_x = col('x').mean(),
               groupby = 'z')
)
┌─────┬───────┐
 z    avg_x 
 ---  ---   
 str  f64   
╞═════╪═══════╡
 "b"  2     
├╌╌╌╌╌┼╌╌╌╌╌╌╌┤
 "a"  0.5   
└─────┴───────┘

Contributing

Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.

License

tidypolars was created by Mark Fairbanks. It is licensed under the terms of the MIT license.

Credits

tidypolars was created with cookiecutter and the py-pkgs-cookiecutter template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tidypolars-0.1.5.tar.gz (8.0 kB view hashes)

Uploaded Source

Built Distribution

tidypolars-0.1.5-py3-none-any.whl (7.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page