Skip to content

API: Expanded resample #13500

Closed
Closed
@chris-b1

Description

@chris-b1

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()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions