Discussion:
[pydata] converting the timezone of a series of Timestamps
Chris Withers
2015-11-27 10:00:33 UTC
Permalink
Hi All,

I feel like I must be missing something simple...
series = pd.Series(pd.date_range('2015-1-1 1:30', periods=3,
freq='min'))
series
0 2015-01-01 01:30:00

1 2015-01-01 01:31:00

2 2015-01-01 01:32:00

dtype: datetime64[ns]
series.tz_localize('America/Chicago').tz_convert('Europe/London')
Traceback (most recent call last):

...

TypeError: index is not a valid DatetimeIndex or PeriodIndex
x.tz_localize('America/Chicago').tz_convert('Europe/London'),
convert_dtype=False)

0 2015-01-01 07:30:00+00:00

1 2015-01-01 07:31:00+00:00

2 2015-01-01 07:32:00+00:00

dtype: object


But, as you can see, this changes the dtype. It's also painfully slow on
any reasonable size frame.


What should I be doing?


Chris
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
tom
2015-11-27 12:53:58 UTC
Permalink
Series.tz_localize / tz_convert operate on the index (checkout the docstring). You’ll want to use the `.dt` namespace

series.dt.tz_localize('America/Chicago’).dt.tz_convert('Europe/London')

I believe this requires pandas 0.17 or newer.

-Tom
Post by Chris Withers
Hi All,
I feel like I must be missing something simple...
series = pd.Series(pd.date_range('2015-1-1 1:30', periods=3, freq='min'))
series
0 2015-01-01 01:30:00
1 2015-01-01 01:31:00
2 2015-01-01 01:32:00
dtype: datetime64[ns]
series.tz_localize('America/Chicago').tz_convert('Europe/London')
...
TypeError: index is not a valid DatetimeIndex or PeriodIndex
series.apply(lambda x: x.tz_localize('America/Chicago').tz_convert('Europe/London'), convert_dtype=False)
0 2015-01-01 07:30:00+00:00
1 2015-01-01 07:31:00+00:00
2 2015-01-01 07:32:00+00:00
dtype: object
But, as you can see, this changes the dtype. It's also painfully slow on any reasonable size frame.
What should I be doing?
Chris
--
You received this message because you are subscribed to the Google Groups "PyData" group.
For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...