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

ENH: enable 'on' keyword for groupby(..).resample() #15021

Closed
jorisvandenbossche opened this issue Dec 31, 2016 · 0 comments
Closed

ENH: enable 'on' keyword for groupby(..).resample() #15021

jorisvandenbossche opened this issue Dec 31, 2016 · 0 comments
Labels
Bug Resample resample method
Milestone

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Dec 31, 2016

Problem description

resample gained a new keyword on to be able to resample based on a column of datetime values instead of the index (which can prevent some use of set_index/reset_index). This feature is however not yet available for resample after a groupby.

Code Sample

In [8]: df = pd.DataFrame({'key': ['A', 'B']*5, 'dates': pd.date_range('2016-01-01', periods=10), 'values': np.random.randn(10)}) 

In [9]: df
Out[9]: 
       dates key    values
0 2016-01-01   A -1.291535
1 2016-01-02   B  0.922945
2 2016-01-03   A -1.039163
3 2016-01-04   B -1.102022
4 2016-01-05   A  1.220347
5 2016-01-06   B  0.265720
6 2016-01-07   A  0.888080
7 2016-01-08   B -0.250236
8 2016-01-09   A  0.485518
9 2016-01-10   B -0.188880

In [11]: df.set_index('dates').groupby('key').resample('D').mean()
Out[11]: 
                  values
key dates               
A   2016-01-01 -1.291535
    2016-01-02       NaN
    2016-01-03 -1.039163
    2016-01-04       NaN
    2016-01-05  1.220347
    2016-01-06       NaN
    2016-01-07  0.888080
    2016-01-08       NaN
    2016-01-09  0.485518
B   2016-01-02  0.922945
    2016-01-03       NaN
    2016-01-04 -1.102022
    2016-01-05       NaN
    2016-01-06  0.265720
    2016-01-07       NaN
    2016-01-08 -0.250236
    2016-01-09       NaN
    2016-01-10 -0.188880

In [12]: df.groupby('key').resample('D', on='dates').mean()
...
TypeError: __init__() got an unexpected keyword argument 'on'

Using pandas master, 0.19.0+289.g1bf94c8

@jorisvandenbossche jorisvandenbossche added this to the Next Major Release milestone Dec 31, 2016
@jreback jreback closed this as completed in 6d2293f Feb 7, 2017
@jreback jreback added Bug and removed Enhancement labels Feb 7, 2017
@jreback jreback modified the milestones: 0.20.0, Next Major Release Feb 7, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
closes pandas-dev#15021

Author: Nicholas Ver Halen <verhalenn@yahoo.com>

Closes pandas-dev#15326 from verhalenn/issue15021 and squashes the following commits:

9fc3b4f [Nicholas Ver Halen] Updated the whatsnew for issue 15021
ec1f316 [Nicholas Ver Halen] Created a test for GH 15021
b8b10b0 [Nicholas Ver Halen] Added the on arg to resample on a grouped dataframe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Resample resample method
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants