I'm using the example you gave in a comment for the df. You cannot use regular datetime.datetime
methods on pandas datetime64
values without using the .dt
accessor. In addition to the example you linked to, you said that you want total_seconds
to refer to the base datetime of 2019/01/01 00:00:00
. A timedelta
must always have some kind of reference point, otherwise it could be any arbitrary value.
import pandas as pd
df1 = pd.DataFrame({'lat':[15.13,12.14,13.215,11.1214,12.14],
'lon': [38.52, 37.536,39.86,38.536,37.536],
'Datetime': pd.to_datetime(['2019-03-09 16:05:07',
'2019-03-15 09:50:07',
'2019-03-09 11:03:47',
'2019-03-10 16:41:18',
'2019-03-09 06:15:27']),
'temp':[23,22,21,22,19]})
# We can just call it once to get a reference to your datum point
base_dt = pd.to_datetime('2019/01/01 00:00:00')
df1['seconds'] = (df1['Datetime'] - base_dt).dt.total_seconds()
to_datetime
will return adatetime64
value that doesn't have the same methods/attributes of a regular python datetime. You'll need to use the.dt
accessor, so something likedf['timestamp'] = df['recorded_time'].dt.
but thentotal_seconds()
is adatetime.timedelta
method from python, so I don't really follow what you expect that to be doing, even if we translated it to pandas. Seconds from when? – Oui