Python pandas convert datetime to timestamp effectively through dt accessor

后端 未结 5 2093
别跟我提以往
别跟我提以往 2021-02-01 14:06

I have a dataframe with some (hundreds of) million of rows. And I want to convert datetime to timestamp effectively. How can I do it?

My sample df:

5条回答
  •  一生所求
    2021-02-01 15:02

    If you don't want to use numpy you can use pure pandas conversions

    df['ts'] = pd.to_timedelta(df['datetime'], unit='ns').dt.total_seconds().astype(int)
    

提交回复
热议问题