Round pandas datetime index?

后端 未结 3 475
名媛妹妹
名媛妹妹 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:32

    For data columns; Use: round_hour(df.Start_time)

    def round_hour(x,tt=''):
        if tt=='M':
            return pd.to_datetime(((x.astype('i8')/(1e9*60)).round()*1e9*60).astype(np.int64))
        elif tt=='H':
            return pd.to_datetime(((x.astype('i8')/(1e9*60*60)).round()*1e9*60*60).astype(np.int64))
        else:   
            return pd.to_datetime(((x.astype('i8')/(1e9)).round()*1e9).astype(np.int64))
    

提交回复
热议问题