ENH: Allow to reset tz from DatetimeIndex holding time representation · Issue #7812 · pandas-dev/pandas (original) (raw)
There looks no easy way to remove tz from tz-aware DatetimeIndex
holding the timestamp represented. What required is inverse operation of tz_localize
.
idx = pd.date_range('2014-01-01 09:00', '2014-01-01 20:00', freq='H', tz='Asia/Tokyo')
idx
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-01 09:00:00+09:00, ..., 2014-01-01 20:00:00+09:00]
# Length: 12, Freq: H, Timezone: Asia/Tokyo
# What I want to do is:
idx.tz_reset()
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-01 09:00:00, ..., 2014-01-01 20:00:00]
# Length: 12, Freq: H, Timezone: None
# This raises TypeError
idx.tz_localize(None)
# TypeError: Already tz-aware, use tz_convert to convert.
# This change the timestamp to UTC
idx.tz_convert(None)
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-01 00:00:00, ..., 2014-01-01 11:00:00]
# Length: 12, Freq: H, Timezone: None
In my case, there are some globally distributed data sources which holds local timezones. And want to merge them and analyze based on local subjective times (business hours, etc).