Closed
Description
related to #3714
tz should not be settable
df=pd.DataFrame({"events":np.ones(len(dates))},index=motor["timestamps"].astype("datetime64[s]"))
df.describe()
events | |
---|---|
count | 2393 |
mean | 1 |
std | 0 |
min | 1 |
25% | 1 |
50% | 1 |
75% | 1 |
max | 1 |
df
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 2393 entries, 2013-05-30 11:58:36 to 2013-06-03 13:30:43
Data columns (total 1 columns):
events 2393 non-null values
dtypes: float64(1)
df.index.tz='Asia/Kolkata'
df.index
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-05-30 17:28:36, ..., 2013-06-03 19:00:43]
Length: 2393, Freq: None, Timezone: Asia/Kolkata
df2=df[df.index.day==3]
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-39-23de8e1402be> in <module>()
----> 1 df2=df[df.index.day==3]
/usr/local/lib/python2.7/dist-packages/pandas/tseries/index.pyc in f(self)
39 utc = _utc()
40 if self.tz is not utc:
---> 41 values = self._local_timestamps()
42 return tslib.get_date_field(values, field)
43 f.__name__ = name
/usr/local/lib/python2.7/dist-packages/pandas/tseries/index.pyc in _local_timestamps(self)
399 values = self.asi8
400 indexer = values.argsort()
--> 401 result = tslib.tz_convert(values.take(indexer), utc, self.tz)
402
403 n = len(indexer)
/usr/local/lib/python2.7/dist-packages/pandas/tslib.so in pandas.tslib.tz_convert (pandas/tslib.c:20949)()
/usr/local/lib/python2.7/dist-packages/pandas/tslib.so in pandas.tslib._get_deltas (pandas/tslib.c:22754)()
/usr/local/lib/python2.7/dist-packages/pandas/tslib.so in pandas.tslib._get_utcoffset (pandas/tslib.c:11327)()
AttributeError: 'str' object has no attribute 'utcoffset'
A temporary fix which i did was to add seconds to data manually while creating the index.
Activity
jreback commentedon Jun 3, 2013
Create a new index with the tz at the beginning;
This kind of assignment is not allowed (and should raise)
nipunbatra commentedon Jun 3, 2013
What would be the best way to create an index in the way i am doing from epoch timestamps and adding tz information.
jreback commentedon Jun 3, 2013
pd.to_datetime(stamps_in_ns,tz=your_tz)
make sure that you stamps are in nanoseconds (prob just multipy by 1e6)
Timestamp will take the nanoseconds and give you the correct timestamp
nipunbatra commentedon Jun 5, 2013
Specifying timezone failed for me. Version 0.11.0
jreback commentedon Jun 5, 2013
@nipunreddevil
from the cross-post
nipunbatra commentedon Jun 5, 2013
Please see timezone is changing, but not the time.
Contrast this with
jreback commentedon Jun 5, 2013
This is why we need a method to do this......
the epoch stamps are 'utc', but after the to_datetime they are not in any timezone
so first have to put them in utc (tz_localize), then convert
nipunbatra commentedon Jun 5, 2013
Great!
20 remaining items