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.
pip install pandas-flavorVerified import paths — ran on the pinned version, not inferred.
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.
Consider using `@pf.register_dataframe_accessor('your_namespace')` to create an accessor class. This namespaces your custom methods under `df.your_namespace.method_name()`.Refer to the Pandas official migration guides for major versions (e.g., Pandas 3.0 migration guide) to understand how these core changes might impact your custom methods. It's recommended to upgrade Pandas incrementally (e.g., to 2.3 first, then 3.0) and resolve any deprecation warnings before relying on `pandas-flavor` methods with new Pandas versions.
Always choose unique and descriptive names for your custom methods and accessors. If there's a potential conflict, consider using an accessor to namespace your methods, reducing the chance of direct name clashes.
Install the library using pip: `pip install pandas-flavor`
Ensure the Python module containing the `@pf.register_dataframe_method` or `@pf.register_dataframe_accessor` decorated code is imported in your script (e.g., `import my_flavor_module`). Verify that the method/accessor name used in the call (e.g., `df.my_custom_method()`) exactly matches the name given in the decorator or the method within the accessor class.
If the method is part of the accessor, ensure you are calling it correctly through the accessor instance (e.g., `df.my_accessor_name.my_method()`). If the method is not defined, add it to your accessor class. If you intended to register a direct DataFrame method, use `@pf.register_dataframe_method` instead of an accessor.