Unable to apply methods on timestamps using Series built-ins Unable to apply methods on timestamps using Series built-ins python python

Unable to apply methods on timestamps using Series built-ins


As Jeff's answer mentions, tz_localize() and tz_convert() act on the index, not the data. This was a huge surprise to me too.

Since Jeff's answer was written, Pandas 0.15 added a new Series.dt accessor that helps your use case. You can now do this:

pd.to_datetime(my_series, unit='ms').dt.tz_localize('UTC').dt.tz_convert('US/Eastern')


tz_localize/tz_convert act on the INDEX of the object, not on the values. Easiest to simply turn it into an index then localize and convert. If you then want a Series back you can use to_series()

In [47]: pd.DatetimeIndex(pd.to_datetime(s,unit='ms')).tz_localize('UTC').tz_convert('US/Eastern')Out[47]: <class 'pandas.tseries.index.DatetimeIndex'>[2014-09-19 17:18:27.178000-04:00, ..., 2014-09-19 10:32:40.544000-04:00]Length: 10, Freq: None, Timezone: US/Eastern


this work fine

pd.to_datetime(my_series,unit='ms', utc=True).dt.tz_convert('US/Eastern')