Convert timedelta64[ns] column to seconds in Python Pandas DataFrame

后端 未结 5 1631
借酒劲吻你
借酒劲吻你 2020-11-28 06:54

A pandas DataFrame column duration contains timedelta64[ns] as shown. How can you convert them to seconds?

0   00:20:32
1   00:23:1         


        
5条回答
  •  天涯浪人
    2020-11-28 07:40

    Use the 'total_seconds()' function :

    df['durationSeconds'] = df['duration'].dt.total_seconds()
    

提交回复
热议问题