4

I am trying to compare a Pandas datetime to a Python datetime.

The code

cur_t = pandas.Timestamp.utcnow()

Gives:

Timestamp('2019-02-14 14:31:40.283415+0000', tz='UTC')

And the code

data_t=indata.data.loc[2000].last_time

Gives:

Timestamp('2019-02-14 14:28:32+0000', tz='UTC')

However, subtracting data_t from cur_t gives TypeError: Timestamp subtraction must have the same timezones or no timezones

What is going on here? Why can't andas compare two times with the same timezone?

grooveplex
  • 2,492
  • 4
  • 28
  • 30
os1
  • 412
  • 1
  • 6
  • 18
  • [This](https://stackoverflow.com/questions/28254408/timestamp-subtraction-of-time-arrays-with-different-timezones) might be helpful – kudeh Feb 14 '19 at 15:08
  • I am also having the same problem: trying to subtract Timestamp('2020-03-26 15:04:05+0000', tz='UTC') from Timestamp('2020-03-26 15:04:05+0000', tz='UTC') gives "TypeError: Timestamp subtraction must have the same timezones or no timezones" – Sushovan Mandal Mar 26 '20 at 16:46
  • @SushovanMandal which version of pandas? Using 1.0.3 I don't get this error – Paul Apr 04 '20 at 02:47
  • @Paul Pandas v0.25.3 – Sushovan Mandal Apr 04 '20 at 06:37

0 Answers0