Skip to main content

Implementation of the DataFrame Standard for pandas and Polars

Project description

Build Status Coverage pre-commit.ci status

DataFrame API Compat

standard-compliant DataFrame

Implementation of the DataFrame Standard for pandas and polars.

What's this?

Please read our blog post! https://data-apis.org/blog/dataframe_standard_rfc/.

Documentation

Please check https://data-apis.org/dataframe-api/draft/API_specification/index.html for the methods supported by the Consortium Dataframe Standard.

How to try this out

Here's an example of how you can try this out:

import polars as pl

df = pl.DataFrame({'a': [1,2,3]})
df_std = df.__dataframe_consortium_standard__()

The object df_std is a Standard-compliant DataFrame. Check the API Specification for the full list of methods supported on it.

Here's an example of a dataframe-agnostic function:

from typing import Any

from dataframe_api._types import SupportsDataFrameAPI

def my_dataframe_agnostic_function(df_non_standard: SupportsDataFrameAPI) -> Any:
    df = df_non_standard.__dataframe_consortium_standard__()
    xp = df.__dataframe_namespace__()

    for column_name in df.column_names:
        new_column = xp.col(column_name)
        new_column = (new_column - new_column.mean()) / new_column.std()
        df = df.assign(new_column.rename(f'{column_name}_scaled'))

    return df.dataframe

As long as you have this package installed, then either a pandas or Polars DataFrame should work with the code above, e.g.:

import pandas as pd
import polars as pl

df_pd = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6]})
df_pl = pl.DataFrame({'a': [1,2,3], 'b': [4,5,6]})

my_dataframe_agnostic_function(df_pd)
my_dataframe_agnostic_function(df_pl)

Compliance with the Standard

This implementation adds some extra syntax and constructs which are not yet part of the Standard. Follow along with the discussion at https://github.com/data-apis/dataframe-api/pull/249.

Installation

pip install dataframe-api-compat

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

dataframe_api_compat-0.1.17.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

dataframe_api_compat-0.1.17-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file dataframe_api_compat-0.1.17.tar.gz.

File metadata

  • Download URL: dataframe_api_compat-0.1.17.tar.gz
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for dataframe_api_compat-0.1.17.tar.gz
Algorithm Hash digest
SHA256 a13027e9a4ba4585535f40c1da3d6c983686e0689cea9e2f70eb5e5b90e5cede
MD5 99f249a08af0c71b413c6c7cc371fcc4
BLAKE2b-256 53f54ae18ea41c5c6e583be4e45f27e281b6636b9c28b1a732e80e03e9e03e14

See more details on using hashes here.

File details

Details for the file dataframe_api_compat-0.1.17-py3-none-any.whl.

File metadata

File hashes

Hashes for dataframe_api_compat-0.1.17-py3-none-any.whl
Algorithm Hash digest
SHA256 38d12f0d8eb2a5a4d1b009e201124abcd250013d6495f83f86701403a9fadcdc
MD5 177f52acc3c952527fc893a953a5fd30
BLAKE2b-256 f9cb1a5545fcb79132336a1d39b68d396890da341c4505e754f4fccbcacbfa9d

See more details on using hashes here.

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