Implementation of the DataFrame Standard for pandas and Polars
Project description
DataFrame API Compat
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
def my_dataframe_agnostic_function(df_non_standard: Any) -> Any:
df = df_non_standard.__dataframe_consortium_standard__()
for column_name in df.column_names:
new_column = df.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
The classes here also have an extra .persist
method, which is not (yet) part of the Standard.
Installation
pip install dataframe-api-compat
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dataframe_api_compat-0.1.25.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ca4536bd5648a2829a1d43bf5404fab1c3578e40934b3d58339739291cff7d4 |
|
MD5 | feadf18a4143bfc01901d6795d430a7a |
|
BLAKE2b-256 | 7444e7c4b193cf764554b792daa67d39aec234a999df4ca8f3cc066c920d4ee6 |
Hashes for dataframe_api_compat-0.1.25-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb1a5874216e3d24b1705f63c66379865174b4ee181975b9c74c136ba2f3c4b9 |
|
MD5 | aa916e2f86104a8121c8aa06ef577d46 |
|
BLAKE2b-256 | c08b50ab0e835613c2d434efc53131baf85dadf31211002c9105e01074017457 |