Skip to content

BUG: groupby with datetime columns #11548

Closed
@superChing

Description

@superChing
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"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions