Get the time spent since midnight in dataframe
问题 I have a dataframe which has a column of type Timestamp. I want to find the time elapsed (in seconds) since midnight as a new column. How to do it in a simple way ? Eg : Input : samples['time'] 2018-10-01 00:00:01.000000000 2018-10-01 00:00:12.000000000 type(samples['time'].iloc[0]) <class 'pandas._libs.tslib.Timestamp'> Output : samples['time_elapsed'] 1 12 回答1: Note that the date part in each row may be other (not from one and the same day), so you can not take any "base date" ( midnight )