Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dataframe rolling issue #262

Open
mattyd100 opened this issue Dec 13, 2024 · 2 comments
Open

dataframe rolling issue #262

mattyd100 opened this issue Dec 13, 2024 · 2 comments

Comments

@mattyd100
Copy link

I have a PintArray in a Dataframe column and I want to calculate the rolling sum and put the values in a new column. The resulting column is an array of floats instead of a PintArray. Is there a way that I can perform the calculation so that the result is a PintArray?

`import numpy as np
import pandas as pd
import pint
import pint_pandas

df = pd.DataFrame(pint_pandas.PintArray(np.arange(10), dtype='pint[in]'), columns = ['A'])
df['B'] = df['A'].rolling(2).sum()
print(df.dtypes)
`

@andrewgsavage
Copy link
Collaborator

you can do this for now
df['B'] = df['A'].rolling(2).sum().astype(df['A'].dtype)
but yea that's not ideal

@andrewgsavage
Copy link
Collaborator

This will need fixing in pandas, so open an issue there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants