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 get_group should be more datelike friendly #5267

Closed
jreback opened this issue Oct 19, 2013 · 0 comments · Fixed by #6872
Closed

BUG: groupby get_group should be more datelike friendly #5267

jreback opened this issue Oct 19, 2013 · 0 comments · Fixed by #6872
Labels
Bug Datetime Datetime data dtype Groupby
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Oct 19, 2013

http://stackoverflow.com/questions/19458361/python-pandas-groupby-date-and-accessing-each-group-by-timestamp

In [2]: df= pd.DataFrame({'DATE' : ['10-Oct-2013', '10-Oct-2013', '10-Oct-2013', '11-Oct-2013', '11-Oct-2013', '11-Oct-2013'],'VAL' : [1,2,3,4,5,6]})

In [3]: df['DATE'] = pd.to_datetime(df['DATE'])

In [4]: df
Out[4]: 
                 DATE  VAL
0 2013-10-10 00:00:00    1
1 2013-10-10 00:00:00    2
2 2013-10-10 00:00:00    3
3 2013-10-11 00:00:00    4
4 2013-10-11 00:00:00    5
5 2013-10-11 00:00:00    6

In [5]: g = df.groupby('DATE')

In [8]: key = g.groups.keys()[0]

In [9]: key
Out[9]: numpy.datetime64('2013-10-09T20:00:00.000000000-0400')

In [10]: g.indices
Out[10]: 
{1381363200000000000L: array([0, 1, 2]),
 1381449600000000000L: array([3, 4, 5])}

In [11]: g.get_group(key.astype('i8'))
Out[11]: 
                 DATE  VAL
0 2013-10-10 00:00:00    1
1 2013-10-10 00:00:00    2
2 2013-10-10 00:00:00    3

so works, but not very friendly
in addition on windows, the following is needed for the selection to succeed

g.get_group(long(key.astype('i8')))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant