Accessing total_seconds() in pandas data column

Viewed 10465

I want to create a new column in a pandas data frame that is the elapsed time from the start of the data frame. I am importing a log file into a data frame which has datatime info, but accessing the total_seconds() function in s_df['delta_t'] is not working. It works if I access the individual elements of the column (s_df['delta_t'].iloc[8].total_seconds()), but I want to create a new column with total_seconds() and my attempts are failing.

s_df['t'] = s_df.index  # s_df['t] is a column of datetime
s_df['delta_t'] = ( s_df['t'] - s_df['t'].iloc[0]) # time since start of data frame
s_df['elapsed_seconds'] = # want column s_df['delta_t'].total_seconds()
1 Answers
Related