How to group a Series by values in pandas?

Martín Fixman picture Martín Fixman · Nov 2, 2015 · Viewed 39.9k times · Source

I currently have a pandas Series with dtype Timestamp, and I want to group it by date (and have many rows with different times in each group).

The seemingly obvious way of doing this would be something similar to

grouped = s.groupby(lambda x: x.date())

However, pandas' groupby groups Series by its index. How can I make it group by value instead?

Answer

luca picture luca · Aug 31, 2016
grouped = s.groupby(s)

Or:

grouped = s.groupby(lambda x: s[x])