How do I round datetime column to nearest quarter hour

后端 未结 4 1508
北海茫月
北海茫月 2020-12-01 00:59

I have loaded a data file into a Python pandas dataframe. I has a datetime column of the format 2015-07-18 13:53:33.280.

What I need to do is create a

4条回答
  •  长情又很酷
    2020-12-01 01:32

    This looks a little nicer

    column.dt. allows the datetime functions for datetime columns, like column.str. does for string-like columns

    datetime-like properties API reference

    import pandas as pd
    
    # test df
    df = pd.DataFrame([{'old_column':pd.Timestamp('2015-07-18 13:53:33.280')}])
    
    df['new_column'] = df['old_column'].dt.round('15min')
    
    df
    

提交回复
热议问题