{"id":4675,"library":"pandas-flavor","title":"pandas-flavor","description":"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.","status":"active","version":"0.8.1","language":"en","source_language":"en","source_url":"https://github.com/pyjanitor-devs/pandas_flavor","tags":["pandas","extension","dataframe","series","accessor","method","api","data-analysis"],"install":[{"cmd":"pip install pandas-flavor","lang":"bash","label":"Install with pip"},{"cmd":"conda install -c conda-forge pandas-flavor","lang":"bash","label":"Install with Conda"}],"dependencies":[{"reason":"Core dependency for extending Pandas objects.","package":"pandas","optional":false},{"reason":"Requires Python 3.10 or newer.","package":"python","optional":false}],"imports":[{"symbol":"register_dataframe_method","correct":"from pandas_flavor import register_dataframe_method"},{"symbol":"register_series_method","correct":"from pandas_flavor import register_series_method"},{"note":"Use 'register_dataframe_accessor' for creating namespaced accessors with multiple methods, which is often preferred by the Pandas community to avoid global method pollution.","wrong":"from pandas_flavor import register_dataframe_method # for creating namespaced methods","symbol":"register_dataframe_accessor","correct":"from pandas_flavor import register_dataframe_accessor"},{"symbol":"register_series_accessor","correct":"from pandas_flavor import register_series_accessor"}],"quickstart":{"code":"import pandas as pd\nimport pandas_flavor as pf\n\n@pf.register_dataframe_method\ndef filter_by_value(df, column, value):\n    \"\"\"Filters a DataFrame to rows where 'column' equals 'value'.\"\"\"\n    return df[df[column] == value]\n\ndf = pd.DataFrame({\n    \"name\": [\"Alice\", \"Bob\", \"Charlie\", \"Alice\"],\n    \"age\": [25, 30, 35, 25]\n})\n\n# Now the custom method is available directly on the DataFrame\nfiltered_df = df.filter_by_value(column=\"name\", value=\"Alice\")\nprint(filtered_df)","lang":"python","description":"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."},"warnings":[{"fix":"Consider using `@pf.register_dataframe_accessor('your_namespace')` to create an accessor class. This namespaces your custom methods under `df.your_namespace.method_name()`.","message":"Directly registering methods (e.g., with `register_dataframe_method`) can lead to 'monkey-patching' where custom functions directly modify Pandas objects. While convenient, the Pandas community often prefers namespaced accessors (`register_dataframe_accessor`) to prevent potential conflicts and maintain clarity, especially in larger projects or libraries.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"While `pandas-flavor` aims for backward compatibility with Pandas versions, recent major Pandas updates (e.g., Pandas 3.0) introduce significant breaking changes in Pandas' core behavior (e.g., dedicated string dtype by default, Copy-on-Write). These changes can subtly affect how user-defined `pandas-flavor` methods and accessors operate on data if not accounted for.","severity":"breaking","affected_versions":"Pandas 3.0.0+"},{"fix":"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.","message":"Registering a method or accessor with a name that already exists on a Pandas DataFrame or Series can lead to unexpected behavior or overwrite existing functionality, although `pandas-flavor` may issue a warning in some cases.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}