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 with datetime columns #11548

Closed
superChing opened this issue Nov 8, 2015 · 2 comments
Closed

BUG: groupby with datetime columns #11548

superChing opened this issue Nov 8, 2015 · 2 comments

Comments

@superChing
Copy link

df=pd.DataFrame(
    [[75,1,'2013-07-15',],
     [44,3,'2014-04-02',],
     [15,2,'2013-05-23',],
     [93,1,'2014-04-04',]] ,columns=['Sales','Store','Date'])

df.Date=pd.to_datetime(df.Date)
gb=df.groupby('Store')
gb.apply(lambda df: pd.Series([1,2,3]))

KeyError: "['Date'] not in index"
If I comment out to_datetime(df.Date) to use string type for date, then it works fine.


more details follows:

INSTALLED VERSIONS
python: 3.4.3.final.0
pandas: 0.17.0


KeyError Traceback (most recent call last)
in ()
8 df.Date=pd.to_datetime(df.Date)
9 gb=df.groupby('Store')
---> 10 gb.apply(lambda df: pd.Series([1,2,3]))

......I omit the intermediate traces for succinct.

/Users/apple/miniconda3/lib/python3.4/site-packages/pandas/core/indexing.py in _convert_to_indexer(self, obj, axis, is_setter)
1119 mask = check == -1
1120 if mask.any():
-> 1121 raise KeyError('%s not in index' % objarr[mask])
1122
1123 return _values_from_object(indexer)

KeyError: "['Date'] not in index"

@hayd
Copy link
Contributor

hayd commented Nov 8, 2015

The bug is from here, as the original columns are not present in the result (quite reasonably):
https://github.com/pydata/pandas/blob/8727182683543d9f953250a454b43dbcaf8ae4a8/pandas/core/groupby.py#L3120-L3129
I don't quite get the intention/need to coerce in this branch...

cc #10265 @bashtage

@jreback
Copy link
Contributor

jreback commented Nov 8, 2015

this is a dupe of #11324

fixed by this: #11460

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

No branches or pull requests

3 participants