pandas-flavor

0.8.1 · active · verified Sun Apr 12

pandas-flavor is a Python library that extends Pandas' API by simplifying the process of registering custom methods and accessors directly onto Pandas DataFrames, Series, and GroupBy objects. It makes it easier to add custom functionality, making it backwards compatible with older versions of Pandas. The current version is 0.8.1, and it is actively maintained with a regular release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to register a custom method directly onto a Pandas DataFrame using the `@pf.register_dataframe_method` decorator. After registration, the method `filter_by_value` becomes available on any DataFrame instance, allowing for chainable operations similar to built-in Pandas methods.

import pandas as pd
import pandas_flavor as pf

@pf.register_dataframe_method
def filter_by_value(df, column, value):
    """Filters a DataFrame to rows where 'column' equals 'value'."""
    return df[df[column] == value]

df = pd.DataFrame({
    "name": ["Alice", "Bob", "Charlie", "Alice"],
    "age": [25, 30, 35, 25]
})

# Now the custom method is available directly on the DataFrame
filtered_df = df.filter_by_value(column="name", value="Alice")
print(filtered_df)

view raw JSON →