We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrated from StackOverflow:
s = pd.Series(pd.date_range('2012-1-1 1:30', periods=3, freq='min', tz='EST'))
You can convert each item individually:
In [86]: s[0] Out[86]: <Timestamp: 2012-01-01 06:30:00> In [87]: s[0].tz_localize('UTC') Out[87]: <Timestamp: 2012-01-01 06:30:00+0000 UTC, tz=UTC>
But when you try to apply across all columns (same with convert_dtype=True):
convert_dtype=True
In [81]: s.apply(lambda x: x.tz_localize('UTC'), convert_dtype=False) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-81-0b4fa5c03650> in <module>() ----> 1 s.apply(lambda x: x.tz_localize('UTC'), convert_dtype=False) /usr/lib/pymodules/python2.7/pandas/core/series.pyc in apply(self, func, convert_dtype, args, **kwds) 2244 return f(self) 2245 -> 2246 mapped = lib.map_infer(self.values, f, convert=convert_dtype) 2247 if isinstance(mapped[0], Series): 2248 from pandas.core.frame import DataFrame /usr/lib/pymodules/python2.7/pandas/lib.so in pandas.lib.map_infer (pandas/lib.c:39084)() <ipython-input-81-0b4fa5c03650> in <lambda>(x) ----> 1 s.apply(lambda x: x.tz_localize('UTC'), convert_dtype=False) AttributeError: 'numpy.datetime64' object has no attribute 'tz_localize'
One workaround is forcing it to be a Timestamp:
In [91]: from pandas.lib import Timestamp In [92]: s.apply(lambda x: Timestamp(x).tz_localize('UTC')) Out[92]: 0 2012-01-01 06:30:00+00:00 1 2012-01-01 06:31:00+00:00 2 2012-01-01 06:32:00+00:00
The text was updated successfully, but these errors were encountered:
Seems to be working now.....
In [8]: s = pd.Series(pd.date_range('2012-1-1 1:30', periods=3, freq='min', tz='EST')) In [9]: s Out[9]: 0 2012-01-01 06:30:00 1 2012-01-01 06:31:00 2 2012-01-01 06:32:00 dtype: datetime64[ns] In [10]: s.apply(lambda x: x.tz_localize('UTC'), convert_dtype=False) Out[10]: 0 2012-01-01 06:30:00+00:00 1 2012-01-01 06:31:00+00:00 2 2012-01-01 06:32:00+00:00 dtype: object In [11]: s.apply(lambda x: x.tz_localize('UTC')) Out[11]: 0 2012-01-01 06:30:00+00:00 1 2012-01-01 06:31:00+00:00 2 2012-01-01 06:32:00+00:00 dtype: object In [12]: s.apply(lambda x: x.tz_localize('UTC'))[0] Out[12]: Timestamp('2012-01-01 06:30:00+0000', tz='UTC')
Sorry, something went wrong.
No branches or pull requests
Migrated from StackOverflow:
You can convert each item individually:
But when you try to apply across all columns (same with
convert_dtype=True
):One workaround is forcing it to be a Timestamp:
The text was updated successfully, but these errors were encountered: