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

BUG: GroupBy.size doesn't attach index name properly if grouped by TimeGrouper #9925

Closed
sinhrks opened this issue Apr 18, 2015 · 0 comments · Fixed by #9936
Closed

BUG: GroupBy.size doesn't attach index name properly if grouped by TimeGrouper #9925

sinhrks opened this issue Apr 18, 2015 · 0 comments · Fixed by #9936
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Apr 18, 2015

import numpy as np
import pandas as pd
import datetime

df = pd.DataFrame({'A': [1, 1, 1, 2, 2, 2], 'B': [1, 2, 3, 4, 5, 6]})
grouped = df.groupby('A')

n = 20
data = np.random.randn(n, 4)
dt_df = pd.DataFrame(data, columns=['A', 'B', 'C', 'D'])
dt_df['key'] = [datetime.datetime(2013, 1, 1), datetime.datetime(2013, 1, 2), pd.NaT,
                datetime.datetime(2013, 1, 4), datetime.datetime(2013, 1, 5)] * 4

# OK, index is named as 'key'
grouped = dt_df.groupby('key')
grouped.size()
# key
#2013-01-01    4
#2013-01-02    4
#2013-01-04    4
#2013-01-05    4
# dtype: int64

# NG (no index name)
grouper = dt_df.groupby(pd.TimeGrouper(key='key', freq='D'))
grouper.size()
#2013-01-01    4
#2013-01-02    4
#2013-01-03    0
#2013-01-04    4
#2013-01-05    4
# dtype: int64

# other agg methods looks ok
grouper.count()
#             A  B  C  D
# key                   
#2013-01-01  4  4  4  4
#2013-01-02  4  4  4  4
#2013-01-03  0  0  0  0
#2013-01-04  4  4  4  4
#2013-01-05  4  4  4  4

ref: #9862

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants