I subtracted two datetime64 columns and got a column of results such as '00:20:32' and '00:08:21.' How do I then convert those datetime64 values to seconds?
            Asked
            
        
        
            Active
            
        
            Viewed 6,051 times
        
    -1
            
            
        - 
                    Please add more information regarding the question. A minimum reprodiclbe example and and expected output would be nice! – Celius Stingher Nov 10 '19 at 21:02
 - 
                    Duplicate? https://stackoverflow.com/questions/14920903/time-difference-in-seconds-from-numpy-timedelta64 – Hallgeir Wilhelmsen Nov 10 '19 at 21:05
 - 
                    Possible duplicate of [Time difference in seconds from numpy.timedelta64](https://stackoverflow.com/questions/14920903/time-difference-in-seconds-from-numpy-timedelta64) ... another, maybe better: [Convert timedelta64 column to seconds in Python Pandas DataFrame](https://stackoverflow.com/questions/26456825/convert-timedelta64ns-column-to-seconds-in-python-pandas-dataframe) – wwii Nov 10 '19 at 21:12
 
2 Answers
2
            
            
        Can you paste the code to make to question more precise ?
Generally you can do that using NumPy timedelta64:
np.timedelta64( timedate1 - timedate2 ,'s')
        Beniamin H
        
- 2,048
 - 1
 - 11
 - 17
 
        dexter103
        
- 58
 - 3
 
1
            Off the top of my head (and with the poor information in the question), if there's a column that contains hours, minutes and seconds, which I will call "time" I would create the following column in the dataframe:
df['full_seconds'] = df['time'].dt.seconds
Or use a simple calculus summing hours, minutes and seconds:
df['full_seconds'] = df['time'].dt.hour * 3600 + df['time'].dt.minute * 60 + df['time'].dt.second
        Celius Stingher
        
- 17,835
 - 6
 - 23
 - 53