{"id":8420,"library":"pint-pandas","title":"Pint-Pandas","description":"Pint-Pandas is a Python library that extends Pandas DataFrames and Series to seamlessly integrate physical quantities with units, leveraging the Pint library. It enables units-aware operations directly within Pandas data structures, ensuring dimensional consistency and preventing common unit errors. The library is actively maintained, with version 0.8.0 released on March 19, 2026. It's important to note that the Pandas integration is still considered experimental by the underlying Pint project.","status":"active","version":"0.8.0","language":"en","source_language":"en","source_url":"https://github.com/hgrecco/pint-pandas","tags":["pandas","units","physical quantities","data science","extension array"],"install":[{"cmd":"pip install pint-pandas","lang":"bash","label":"Install with pip"},{"cmd":"conda install -c conda-forge pint-pandas","lang":"bash","label":"Install with Conda"}],"dependencies":[{"reason":"Core dependency for DataFrame and Series extension. Pint-Pandas 0.6+ supports Pandas 3.0+.","package":"pandas","optional":false},{"reason":"Core dependency for physical quantity and unit management. Pint-Pandas 0.6+ requires Pint 0.24+.","package":"pint","optional":false}],"imports":[{"symbol":"pandas","correct":"import pandas as pd"},{"symbol":"pint","correct":"import pint"},{"note":"pint_pandas is a separate package, not a submodule of pint.","wrong":"from pint import pandas","symbol":"pint_pandas","correct":"import pint_pandas"}],"quickstart":{"code":"import pandas as pd\nimport pint\nimport pint_pandas\n\n# Create a DataFrame with PintArrays as columns\ndf = pd.DataFrame({\n    \"torque\": pd.Series([1.0, 2.0, 2.0, 3.0], dtype=\"pint[lbf ft]\"),\n    \"angular_velocity\": pd.Series([1.0, 2.0, 2.0, 3.0], dtype=\"pint[rpm]\"),\n})\n\nprint(\"Original DataFrame:\\n\", df)\nprint(\"\\nData Types:\\n\", df.dtypes)\n\n# Perform units-aware operations\ndf['power'] = df['torque'] * df['angular_velocity']\n\nprint(\"\\nDataFrame with calculated 'power':\\n\", df)\nprint(\"\\nData Types after calculation:\\n\", df.dtypes)\n\n# Access magnitudes or convert units\nprint(\"\\nPower in Watts:\\n\", df['power'].pint.to('W'))","lang":"python","description":"This quickstart demonstrates how to create a Pandas DataFrame with unit-aware columns using `pint[unit]` dtypes. It then shows how to perform arithmetic operations that automatically handle unit conversions and dimensional analysis. Finally, it illustrates how to convert units of a Series using the `.pint` accessor."},"warnings":[{"fix":"Always refer to the latest documentation and test thoroughly, especially for critical applications.","message":"The Pandas integration is officially considered 'experimental'. While functional, some edge cases or advanced Pandas features might not behave as expected or could change in future releases.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If units are not needed, explicitly extract magnitudes using `.pint.magnitude`. If units are critical, ensure operations are units-aware or explicitly convert units before array conversion.","message":"When downcasting a PintArray to a NumPy array (e.g., implicitly in some Pandas operations), the unit information will be stripped, resulting in a `UnitStrippedWarning`. This can lead to loss of unit context if not handled explicitly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check the `pint-pandas` changelog and documentation for the exact compatible versions of `pandas` and `pint` for your desired `pint-pandas` version. Ensure your Python environment meets the minimum `requires_python` of `pint-pandas` and `pandas`.","message":"Pint-Pandas has specific minimum version requirements for both `pandas` and `pint` that evolve with new releases. For instance, `pint-pandas` 0.6 requires `pandas` >= 2.2 and `pint` >= 0.24. Pandas 3.0 also introduced significant breaking changes and mandates Python 3.11+.","severity":"breaking","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install pint-pandas` or `conda install -c conda-forge pint-pandas` to install the package.","cause":"The `pint-pandas` package has not been installed. Users sometimes install `pint` but forget to install its Pandas integration package.","error":"ModuleNotFoundError: No module named 'pint_pandas'"},{"fix":"After loading data, use the `.pint.quantify()` or `.pint.convert_object_dtype()` accessor methods to correctly convert the `object` columns into `PintArray` dtypes. For example: `df = df.pint.quantify(level=-1)` if units are in the header, or `df = df.pint.convert_object_dtype()` for Series of Quantities.","cause":"Columns were created or loaded (e.g., from CSV) containing `pint.Quantity` objects but were not explicitly cast to `PintArray` dtypes, leading Pandas to infer an `object` dtype. Operations may then fail to be units-aware.","error":"DataFrame `dtype` is `object` instead of `pint[unit]` for columns expected to have units."},{"fix":"Instead of in-place operations, reassign the result of the method. For example, use `s = s.pint.to('new_unit')` instead of `s.pint.ito('new_unit')`.","cause":"Due to how Pint-Pandas handles delegated methods for its Series accessor, direct in-place modification might not work as intuitively expected for all methods.","error":"In-place Series operations (e.g., `s.pint.ito('new_unit')`) appear to do nothing."}]}