Pandas dataframe datetime to time then to seconds

后端 未结 2 1714
说谎
说谎 2020-12-10 23:14

I have a dataframe. A column contains timestamps. I would like to remove dates and convert the time to seconds.

First I converted them to datetime:

I         


        
2条回答
  •  伪装坚强ぢ
    2020-12-10 23:21

    Since you are converting it to datetime series, simply use basic maths to get the seconds i.e

    df_time = pd.to_datetime(df["Timestamp"])
    
    (df_time.dt.hour*60+df_time.dt.minute)*60 + df_time.dt.second
    
    0    47340
    1    47460
    2    47580
    3    47700
    Name: Timestamp, dtype: int64
    

提交回复
热议问题