Skip to content

ENH: allow datelike to be aggregated in resample #6409

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

Closed
jreback opened this issue Feb 19, 2014 · 2 comments
Closed

ENH: allow datelike to be aggregated in resample #6409

jreback opened this issue Feb 19, 2014 · 2 comments
Labels
Closing Candidate May be closeable, needs more eyeballs Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions Enhancement Resample resample method Timedelta Timedelta data type

Comments

@jreback
Copy link
Contributor

jreback commented Feb 19, 2014

http://stackoverflow.com/questions/21878599/pandas-drops-timestamp-columns-in-resample

init_time=pd.date_range(start='2010-01-01 00:00', end='2010-01-05 00:00', freq='12H')
valid_time=pd.date_range(start='2010-01-01 00:00', end='2010-01-05 00:00', freq='12H')
data = np.random.random(len(valid_time))
frame = pd.DataFrame(index=valid_time, data=data)
frame['init_time'] = init_time

Works, but a little hacky

In [48]: numeric = frame.resample('D',how='mean')

In [49]: datelike = frame.loc[:,frame.dtypes.isin([np.dtype('datetime64[ns]')])]

In [50]: datelike = datelike.resample('D',
         how=lambda x: Timestamp(x.view('i8').mean()))

In [51]: concat([numeric,datelike],axis=1)
Out[51]: 
                   0           init_time
2010-01-01  0.798880 2010-01-01 06:00:00
2010-01-02  0.859781 2010-01-02 06:00:00
2010-01-03  0.515503 2010-01-03 06:00:00
2010-01-04  0.505557 2010-01-04 06:00:00
2010-01-05  0.979835 2010-01-05 00:00:00

[5 rows x 2 columns]
@jreback jreback added this to the 0.15.0 milestone Feb 19, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@mroeschke mroeschke changed the title ENH: allow datelike to be aggregated in groupbys ENH: allow datelike to be aggregated in resample Mar 31, 2020
@mroeschke mroeschke added Resample resample method and removed Groupby labels Mar 31, 2020
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@jbrockmendel
Copy link
Member

frame.resample("D").mean() now retains the dt64 column. i think this is closable?

@jbrockmendel jbrockmendel added the Closing Candidate May be closeable, needs more eyeballs label Feb 25, 2023
@MarcoGorelli
Copy link
Member

yeah this seems to work now

In [24]: frame
Out[24]:
                            0           init_time
2010-01-01 00:00:00  0.110461 2010-01-01 00:00:00
2010-01-01 12:00:00  0.063558 2010-01-01 12:00:00
2010-01-02 00:00:00  0.016708 2010-01-02 00:00:00
2010-01-02 12:00:00  0.685998 2010-01-02 12:00:00
2010-01-03 00:00:00  0.607047 2010-01-03 00:00:00
2010-01-03 12:00:00  0.090777 2010-01-03 12:00:00
2010-01-04 00:00:00  0.871941 2010-01-04 00:00:00
2010-01-04 12:00:00  0.928479 2010-01-04 12:00:00
2010-01-05 00:00:00  0.272012 2010-01-05 00:00:00

In [25]: frame.resample('D').mean()
Out[25]:
                   0           init_time
2010-01-01  0.087010 2010-01-01 06:00:00
2010-01-02  0.351353 2010-01-02 06:00:00
2010-01-03  0.348912 2010-01-03 06:00:00
2010-01-04  0.900210 2010-01-04 06:00:00
2010-01-05  0.272012 2010-01-05 00:00:00

closing then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions Enhancement Resample resample method Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

4 participants