Truncate `TimeStamp` column to hour precision in pandas `DataFrame`

后端 未结 2 1342
轻奢々
轻奢々 2020-12-02 12:58

I have a pandas.DataFrame called df which has an automatically generated index, with a column dt:

df[\'dt\'].dtype, df         


        
2条回答
  •  清歌不尽
    2020-12-02 13:52

    A method I've used in the past to accomplish this goal was the following (quite similar to what you're already doing, but thought I'd throw it out there anyway):

    df['dt2'] = df['dt'].apply(lambda x: x.replace(minute=0, second=0))
    

提交回复
热议问题