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()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…