hgrecco / pint-pandas

Pandas support for pint
Other
169 stars 42 forks source link

How to access ureg in df.pint? #115

Closed deeplook closed 2 years ago

deeplook commented 2 years ago

I have a simple function I want to use on a dataframe's rows with df.apply(), say:

def func(col1, col2):
    return 2 * (col1 * col2) - Q_("5 kg")

But I get this error because this mixes two unit registries, so the question is how to access the one inside the dataframe?

ValueError: Cannot operate with Quantity and Quantity of different registries.

deeplook commented 2 years ago

Solved it using sth. like pint_pandas.PintType.ureg = ureg as suggested in https://github.com/hgrecco/pint-pandas/blob/master/notebooks/pint-pandas.ipynb.