Round pandas datetime index?

后端 未结 3 468
名媛妹妹
名媛妹妹 2020-12-11 07:58

I am reading multiple spreadsheets of timeseries into a pandas dataFrame and concatenating them together with a common pandas datetime index. The datalogger that logged the

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 08:49

    Issue 4314 mentioned by Jeff is now closed and round() method was added for DatetimeIndex, Timestamp, TimedeltaIndex and Timedelta in pandas 0.18.0. Now we can do the following:

    In[109]: index = pd.DatetimeIndex([pd.Timestamp('20120827 12:05:00.002'), pd.Timestamp('20130101 12:05:01'), pd.Timestamp('20130712 15:10:30'), pd.Timestamp('20130712 15:10:31')])
    
    In[110]: index.values
    Out[110]: 
    array(['2012-08-27T12:05:00.002000000', '2013-01-01T12:05:01.000000000',
           '2013-07-12T15:10:30.000000000', '2013-07-12T15:10:31.000000000'], dtype='datetime64[ns]')
    
    In[111]: index.round('min')
    Out[111]: 
    DatetimeIndex(['2012-08-27 12:05:00', '2013-01-01 12:05:00',
                   '2013-07-12 15:10:00', '2013-07-12 15:11:00'],
                  dtype='datetime64[ns]', freq=None)
    

    round() accepts frequency parameter. String aliases for it are listed here.

提交回复
热议问题