Reputation: 1913
I have an integer indexed pd.Series
with dtype datetime64[ns]
called timestamps
. (timestamps
is sorted but this shouldn't matter)
I would like to calculate another series called first_on_day
with the same index and the same dtype that represents the earliest time on the day.
The following code works:
first_on_day = timestamps.groupby(timestamps.dt.date).apply(lambda series: pd.Series(series.min(), index=series.index))
Is there a more idiomatic way to doing this?
Related: Pandas aggregate values by years but keep original TimeSeries index
Upvotes: 0
Views: 442
Reputation: 23146
IIUC, you want:
timestamps.groupby(timestamps.dt.date).transform("min")
Upvotes: 1