简体   繁体   中英

handling a different types of Timestamp in Dask or Pandas in python

I want to do the following operation-:

(pd.to_datetime('2014-04-15 09:30:39+02:00') - pd.Timestamp("1970-01-01"))

but it throws this error-: TypeError: Cannot subtract tz-naive and tz-aware datetime-like objects.

this line of code works with the following timestamps

1. (pd.to_datetime('2014-04-14 00:00:00') - pd.Timestamp("1970-01-01"))
2. (pd.to_datetime('2014-04-15 09:30') - pd.Timestamp("1970-01-01"))
3. (pd.to_datetime('2014-04-15') - pd.Timestamp("1970-01-01"))

is there any good way to convert the timestamp into the 1st (as there are three)?

what could be the reason for this error?

thanks

Given the default behavior for pd.to_datetime and timestamp() is to assume UTC when set to True, unless specified otherwise, and given in pd.Timestamp you are not specifying it, therefore, assuming UTC, you can use:

(pd.to_datetime('2014-04-15 09:30:39+02:00') - pd.Timestamp("1970-01-01",tz='UTC'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM