Skip to main content

Fast Polars functions that Ethan likes to use.

Project description

polars-ethan is a Python library that adds useful functions for use with Polars. This is also my first published package, so it is a good exercsie.

Features

Demean

The demean function subtracts the mean from each non-Null value in a Series, preserving Null values.

import polars as pl
from ethanpolars import demean

# Sample data...
cameras = pl.DataFrame(
    {
        "brand": ["Leica", "Leica", "Leica", "Mamiya", "Mamiya", "Mamiya"],
        "model": ["MP", "M4", "M7", "RB67", "7II", "645 Pro"],
        "price": [6000, 10000, None, 600, 3000, 900],
    }
)

cameras = cameras.with_columns(
    pl.col('price')
    .map_batches(demean)
    .over(pl.col("brand"))
    .alias('d_price')
)

print(cameras)

Output:

┌────────┬─────────┬───────┬─────────┐
│ brand  ┆ model   ┆ price ┆ d_price │
│ ---    ┆ ---     ┆ ---   ┆ ---     │
│ str    ┆ str     ┆ i64   ┆ f64     │
╞════════╪═════════╪═══════╪═════════╡
│ Leica  ┆ MP      ┆ 6000  ┆ -2000.0 │
│ Leica  ┆ M4      ┆ 10000 ┆ 2000.0  │
│ Leica  ┆ M7      ┆ null  ┆ null    │
│ Mamiya ┆ RB67    ┆ 600   ┆ -900.0  │
│ Mamiya ┆ 7II     ┆ 3000  ┆ 1500.0  │
│ Mamiya ┆ 645 Pro ┆ 900   ┆ -600.0  │
└────────┴─────────┴───────┴─────────┘

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

polars_ethan-0.3.0.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polars_ethan-0.3.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file polars_ethan-0.3.0.tar.gz.

File metadata

  • Download URL: polars_ethan-0.3.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.9

File hashes

Hashes for polars_ethan-0.3.0.tar.gz
Algorithm Hash digest
SHA256 bc41e322a9082ca092c54f1379ea6b18bf68ecc4de1a137c5b7eead6f75c8f4c
MD5 9c7b6060e62c99c5b8911ec074a9d231
BLAKE2b-256 93e6eb07d82ed4b4e706d9d8b7b9678b5a04e0a2dcc1ec27a87fa8d4e6b8ded8

See more details on using hashes here.

File details

Details for the file polars_ethan-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for polars_ethan-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2cd45d79cd2fae7fbafcf739828c9ec9cd3c950d38eefac2217b24f0c9cb86b
MD5 c4bd0472d42fd29ba49fc976f40d3534
BLAKE2b-256 7796c17366844dadcb07992e18011a990ef2a8f23a4a4e69670d3adb617ce424

See more details on using hashes here.

Supported by

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