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

API: Expanded resample #13500

Closed
chris-b1 opened this issue Jun 23, 2016 · 1 comment
Closed

API: Expanded resample #13500

chris-b1 opened this issue Jun 23, 2016 · 1 comment
Labels
API Design Resample resample method

Comments

@chris-b1
Copy link
Contributor

Idea after seeing the gitter between @ssanderson and @jorisvandenbossche

Consider this data:

In [13]: df = pd.DataFrame({'date': pd.date_range('2015-01-01', freq='W', periods=5),
                            'a': np.arange(5)}, 
                            index=pd.MultiIndex.from_arrays([
                                [1,2,3,4,5], 
                                pd.date_range('2015-01-01', freq='W', periods=5)], 
                            names=['v','d']))

In [14]: df
Out[14]: 
              a       date
v d                       
1 2015-01-04  0 2015-01-04
2 2015-01-11  1 2015-01-11
3 2015-01-18  2 2015-01-18
4 2015-01-25  3 2015-01-25
5 2015-02-01  4 2015-02-01

Right now to resample by MultiIndex level 'd' or column 'date' it would be:

In [15]: df.groupby(pd.TimeGrouper(key='date', freq='M')).sum()
Out[15]: 
            a
date         
2015-01-31  6
2015-02-28  4

In [16]: df.groupby(pd.TimeGrouper(level='d', freq='M')).sum()
Out[16]: <same>

What if we instead allowed this as a convenience?

In [17]: df.resample('M', level='d').sum()
In [17]: df.resample('M', key='date').sum()
@jreback
Copy link
Contributor

jreback commented Jun 23, 2016

yes this should be a very easy add

@jreback jreback added this to the Next Major Release milestone Jun 23, 2016
@chris-b1 chris-b1 mentioned this issue Aug 11, 2016
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Resample resample method
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants