Issue
A Pandas DataFrame
contains column named "date"
that contains non-unique datetime
values.
I can group the lines in this frame using:
data.groupby(data['date'])
However, this splits the data by the datetime
values. I would like to group these data by the year stored in the "date" column. This page shows how to group by year in cases where the time stamp is used as an index, which is not true in my case.
How do I achieve this grouping?
Solution
I'm using pandas 0.16.2. This has better performance on my large dataset:
data.groupby(data.date.dt.year)
Using the dt
option and playing around with weekofyear
, dayofweek
etc. becomes far easier.
Answered By - DACW
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.