Consider a series of datetimes
s = pd.Series(pd.to_datetime(['2010-08-05']))
s
0 2010-08-05
dtype: datetime64[ns]
I want to create a series of period objects and get an attribute end_time.
sp = s.dt.to_period('M')
sp
0 2010-08
dtype: object
Now I am accessing the attribute end_time.
sp.dt.end_time
0 2010-08-31
dtype: datetime64[ns]
I was almost satisfied until I realized what end_timeshould be Timestamp('2010-08-31 23:59:59.999999999'), notTimestamp('2010-08-31 00:00:00')
Ok so i compared
sp.iloc[0].end_time
Timestamp('2010-08-31 23:59:59.999999999')
sp.dt.end_time.iloc[0]
Timestamp('2010-08-31 00:00:00')
sp.iloc[0].end_time == sp.dt.end_time.iloc[0]
False
It makes no sense to me. Clearly, the periods are correct. How can I get pd.Series.dt.end_timeto return the right thing?
source
share