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

Groupby aggregation of date/datetime columns returns datetime64 rather than numeric type #11444

Closed
michaelbilow opened this issue Oct 27, 2015 · 1 comment
Labels
Datetime Datetime data dtype Groupby
Milestone

Comments

@michaelbilow
Copy link

import pandas as pd
import datetime
u = [datetime.datetime(2015, x, 1) for x in range(12)]
v = list('aaabbbbbbccd')
df = pd.DataFrame('X':v, 'Y':u)
df.groupby('X')['Y'].agg(len)
## Returns the following:
X
a   1970-01-01 00:00:00.000000003
b   1970-01-01 00:00:00.000000006
c   1970-01-01 00:00:00.000000002
d   1970-01-01 00:00:00.000000001

You can fix the problem by casting the dates to strings before groupby/agg, but if you try to cast the returned datetimes to ints, errors go off in some versions of pandas. Either way, aggregating by length should always return an int. Also, this may be similar to #11442, which was just posted.

@jreback
Copy link
Contributor

jreback commented Oct 27, 2015

this is a dupe of #10972

thanks for the report

@jreback jreback closed this as completed Oct 27, 2015
@jreback jreback added Datetime Datetime data dtype Groupby labels Oct 27, 2015
@jreback jreback added this to the 0.20.0 milestone Feb 27, 2017
jreback added a commit to jreback/pandas that referenced this issue Feb 27, 2017
jreback added a commit to jreback/pandas that referenced this issue Feb 27, 2017
jreback added a commit to jreback/pandas that referenced this issue Feb 27, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Groupby
Projects
None yet
Development

No branches or pull requests

2 participants