pandas - Python Data Frame Time Delta -


i stuck on problem , figured time ask help/advice. have data frame has column named created_on consists of datetime. goal figure out how time in seconds has passed since previous row.

i have run code below reason, seconds giving me way off. code below outputs data frame additional column named timediff consisting of difference in seconds if any.

             created_on                                   1. 2014-12-08 03:29:08                      2. 2014-12-08 03:29:08                   3. 2015-02-09 00:10:01     

output

time_diff   1. 0.0  2. 0.0  3. 74453.0 

code:

golden['timediff'] = golden.created_on.diff().dt.seconds 

iiuc looking series.dt.total_seconds():

in [45]: golden['timediff'] = golden.created_on.diff().dt.total_seconds()  in [46]: golden out[46]:            created_on   timediff 0 2014-12-08 03:29:08        nan 1 2014-12-08 03:29:08        0.0 2 2015-02-09 00:10:01  5431253.0 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -