Code Sample, a copy-pastable example if possible

# Your code here
df = pd.DataFrame()
df["time"] = pd.date_range(start="2017-01-01", end="2018-01-01", freq="D", tz="utc")
df["now"] = pd.datetime.utcnow()
df["now"] - df["time"] #raises ValueError: Incompatible tz's on datetime subtraction ops

Problem description

Calling df["now"].dt.tz returns None, meaning that pd.datetime.utcnow() has not been explicitly localized to utc. Since pd.datetime.now() is tz-naive, it is useful to have a similar function which returns the current time with timezone localization for operating on tz-aware datetimes.

Expected Output

df["now"].dt.tz returns <UTC>

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.2.final.0 python-bits: 64 OS: Linux OS-release: 4.9.0-5-amd64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 pandas: 0.22.0 pytest: 3.2.1 pip: 9.0.1 setuptools: 36.5.0.post20170921 Cython: 0.26.1 numpy: 1.14.0 scipy: 0.19.1 pyarrow: None xarray: None IPython: 6.1.0 sphinx: 1.6.3 patsy: 0.4.1 dateutil: 2.6.1 pytz: 2018.3 blosc: None bottleneck: 1.2.1 tables: 3.4.2 numexpr: 2.6.2 feather: None matplotlib: 2.0.2 openpyxl: 2.4.8 xlrd: 1.1.0 xlwt: 1.3.0 xlsxwriter: 0.9.8 lxml: 3.8.0 bs4: 4.6.0 html5lib: 0.9999999 sqlalchemy: 1.1.13 pymysql: None psycopg2: 2.7.3.2 (dt dec pq3 ext lo64) jinja2: 2.9.6 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None

Comment From: jreback

you need to localize. despite its name datetime.utcnow() does not return a tz-aware value. this is a standard library problem where there is no concrete impementation of timezones.

In [4]: df.dtypes
Out[4]: 
time    datetime64[ns, UTC]
now          datetime64[ns]
dtype: object

``` In [10]: df['now'].dt.tz_localize('UTC') Out[10]: 0 2018-02-14 10:59:27.808468+00:00 1 2018-02-14 10:59:27.808468+00:00 2 2018-02-14 10:59:27.808468+00:00 3 2018-02-14 10:59:27.808468+00:00 4 2018-02-14 10:59:27.808468+00:00 5 2018-02-14 10:59:27.808468+00:00 ...
360 2018-02-14 10:59:27.808468+00:00 361 2018-02-14 10:59:27.808468+00:00 362 2018-02-14 10:59:27.808468+00:00 363 2018-02-14 10:59:27.808468+00:00 364 2018-02-14 10:59:27.808468+00:00 365 2018-02-14 10:59:27.808468+00:00 Name: now, Length: 366, dtype: datetime64[ns, UTC]

````