Converting timestamp to seconds in pandas dataframe

Viewed 16

I have a dataframe containing timestamps as follows:

Timestamp, Position, Speed

1662189653, 53, 20
1662189669, 34, 12
1662189688, 21, 19

I would like to convert this timestamp to a value in seconds, and print this in a list of seconds. How do I select each timestamp in the dataframe and convert this into seconds?

I am aware of the datetime module and have tried it using the following loop:

time = []

for time in t:

    dt_object = datetime.fromtimestamp(time)
    print (dt_object)
    dt = datetime(dt_object)
    epoch_time = datetime(1970, 1, 1)
    delta = (dt - epoch_time)
    time.append(delta)

Which raises the following error:

TypeError: an integer is required (got type datetime.datetime)
0 Answers
Related