Skip to main content

No project description provided

Project description

BearDataClass

Problem

A dataframe (in pandas or polars) often simply represents a collection of dataclass instances. However, we cannot access the new dataframe using dataclass attributes.

Solution (How to use)

This package proposes the simple BearDataClass Mixin-class. Dataclasses inheriting from it come with a few convenience methods to operate on dataframes based on dataclasses:

from dataclasses import dataclass
from beardataclass import BearDataClass

@dataclass
class Foo(BearDataClass):
    x: int

df = Foo.create_pandas_df([Foo(1), Foo(2)])
df.loc[:, Foo.fields().x] *= 2
recreated = Foo.from_row(df.iloc[0,:])

How to install

Run pip install BearDataClass

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

beardataclass-0.2.1.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

beardataclass-0.2.1-py3-none-any.whl (2.2 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