ENH: Allow to reset tz from DatetimeIndex holding time representation
See original GitHub issueThere 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).
Issue Analytics
- State:
- Created 9 years ago
- Comments:20 (20 by maintainers)
Top Results From Across the Web
Convert pandas timezone-aware DateTimeIndex to naive ...
At display time, the data is offset appropriately and +01:00 (or similar) is added to the string. Stripping off the tz_info value (using...
Read more >pandas.DatetimeIndex.tz_localize
This method takes a time zone (tz) naive Datetime Array/Index object and makes this time zone aware. It does not move the time...
Read more >What's New — pandas 0.18.1 documentation - API Manual
API breaking change to the .resample method to make it more .groupby like, ... tz-aware Timestamp and DatetimeIndex now removes timezone holding local...
Read more >pandas-docs-zh
Easy handling of missing data (represented as NaN) in floating point as well ... .rolling() objects are now time-series aware and can accept...
Read more >pandas: powerful Python data analysis toolkit - Amazon S3
The default Index printing has changed to a more uniform format, ... for tz-aware Timestamp and DatetimeIndex now removes timezone holding.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hmm, both
tz_localize
andtz_convert
“converts” something, the actual behavior should be considered.tz_localize
“converts” timezone holding time representation (holding subjective time and change absolute time).tz_convert
“converts” timezone holding UTC time (holding absolute time and change subjective time).The required operation is “holding subjective time and reset timezone”, thus I feel
tz_localize(None)
is more natural. If we usetz_convert(None)
for this operation,tz_convert
has inconsistency which sometimes convert subjective time, otherwise convert absolute time.Thanks, looks more clear. Docs in #7852 uses US timezone and different hours from UTC offset, there should be no problem.