Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas can't compare offset-naive and offset-aware datetimes

I have df like this:

df['Time']
2017-08-06 11:00:00+00:00
2017-08-08 15:00:00+00:00
2017-08-10 04:00:00+00:00
2017-08-12 23:00:00+00:00
2017-08-08 15:00:00+00:00

I want to slice it with condition

mask1=df['Time'] > datetime.datetime.strptime('2017-08-12', "%Y-%m-%d")

I get an error like

can't compare offset-naive and offset-aware datetimes

Somehow I have to convert df['Time'] to offset-naive.
Please help me fix this.

like image 869
Bharat Sharma Avatar asked Sep 19 '17 08:09

Bharat Sharma


1 Answers

It seems you need:

df['Time'] = df['Time'].dt.tz_localize(None)

Or:

df['Time'] = df['Time'].dt.tz_convert(None)

Or:

df['Time'] = df['Time'].astype('datetime64[ns]')

See also tz aware dtypes.

like image 136
jezrael Avatar answered Nov 14 '22 07:11

jezrael