Skip to content

ENH: pivot_table can now accept Grouper #6913

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

Merged
merged 1 commit into from
Apr 27, 2014
Merged

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Apr 19, 2014

pivot_table can accept Grouper by index and columns kw.

>>> df = pd.DataFrame({
    'Branch' : 'A A A A A A A B'.split(),
    'Buyer': 'Carl Mark Carl Carl Joe Joe Joe Carl'.split(),
    'Quantity': [1,3,5,1,8,1,9,3],
    'Date' : [datetime(2013,11,1,13,0), datetime(2013,9,1,13,5),
              datetime(2013,10,1,20,0), datetime(2013,10,2,10,0),
              datetime(2013,11,1,20,0), datetime(2013,10,2,10,0),
              datetime(2013,10,2,12,0), datetime(2013,12,5,14,0)],
    'PayDay' : [datetime(2013,10,4,0,0), datetime(2013,10,15,13,5),
                datetime(2013,9,5,20,0), datetime(2013,11,2,10,0),
                datetime(2013,10,7,20,0), datetime(2013,9,5,10,0),
                datetime(2013,12,30,12,0), datetime(2013,11,20,14,0),]})

>>> pd.pivot_table(df, index=pd.Grouper(freq='M', key='Date'),
                     columns=pd.Grouper(freq='M', key='PayDay'),
                     values='Quantity', aggfunc=np.sum)
PayDay      2013-09-30  2013-10-31  2013-11-30  2013-12-31
Date                                                      
2013-09-30         NaN           3         NaN         NaN
2013-10-31           6         NaN           1           9
2013-11-30         NaN           9         NaN         NaN
2013-12-31         NaN         NaN           3         NaN

@jorisvandenbossche
Copy link
Member

Looks usefull at first glance!

  • Can you in the future first open an issue to propose the functionality? (unless there is already one?) In this case I personally think it is useful functionality, but if we would decide this is out of scope for pandas (or some other reason to not include it), it would be a bit pity for your efforts in the PR.
  • Can you also add something to the docs (somewhere in reshaping.rst)
  • I suppose this is only usefull for datetime-like columns? Maybe explain this better then?

@@ -176,6 +176,8 @@ API Changes
- ``.quantile`` on a ``datetime[ns]`` series now returns ``Timestamp`` instead
of ``np.datetime64`` objects (:issue:`6810`)

- ``pivot_table``'s ``index`` and ``columns`` keywords can now accept ``Grouper`` (:issue:`6913`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the blank line above. And can you move this to 'Improvements' instead of 'API changes'?

@jreback jreback added this to the 0.14.0 milestone Apr 21, 2014
@jreback
Copy link
Contributor

jreback commented Apr 21, 2014

@sinhrks ping when you update

@sinhrks
Copy link
Member Author

sinhrks commented Apr 26, 2014

@jreback @jorisvandenbossche Updated the points and rebased. Pls check?

@jorisvandenbossche
Copy link
Member

@jreback docs are OK now for me. But I don't really have a judgement on the implemenation. OK for you?

jreback added a commit that referenced this pull request Apr 27, 2014
ENH: pivot_table can now accept Grouper
@jreback jreback merged commit 89502fc into pandas-dev:master Apr 27, 2014
@jreback
Copy link
Contributor

jreback commented Apr 27, 2014

thanks @sinhrks

@sinhrks sinhrks deleted the pivotg branch April 28, 2014 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Groupby Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants