Skip to content

BUG: using pd.Grouper with a multi-level index and specifying level (and freq) buggy #7885

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 Jul 31, 2014 · 0 comments · Fixed by #7923
Closed
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Groupby
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Jul 31, 2014

http://stackoverflow.com/questions/25050015/resampling-over-dates-in-both-levels-of-a-multiindex-pandas-dataframe/25050074#25050074

from datetime import date
d0 = date.today() - timedelta(days=14)
dates = pd.date_range(d0, date.today())
date_index = pd.MultiIndex.from_product([dates, dates], names=['cohort_date', 'event_date'])
df = pd.DataFrame(np.random.randint(0, 100, 225), index=date_index)

Works

df.reset_index().groupby([pd.Grouper(key='cohort_date',freq='W'),pd.Grouper(key='event_date',freq='W')]).sum()

This should be equivalent, but raises

df.groupby([pd.Grouper(level='cohort_date',freq='W'),pd.Grouper(level='event_date',freq='W')]).sum()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant