python - Indexing with DatetimeIndex returning Int64Index? -
I am running in a strange problem with the following versions:
- Panda: < Code> 0.14.1
- Python:
3.4.1 :: Anaconda 2.0.1 (x86_64)
I have Is a series like the following (available data)
& gt; My_series.head () Timestamp 2014-10-14 19:00 00.85000-04: 00 6.4400 2014-10-14 19:00 00: 07.094000-04: 00 6.4400 2014-10-14 19: 00: 07.10 9000- 04: 00 5.9584 2014-10-14 19:00: 07.211000-04: 00 6.2160 2014-10-14 19: 00: 07.410000-04: 00 6.4400 Name: Quantity, dtype: float64 < P> Index is
DatetimeIndex :
& gt; My_series.index & lt; Class 'pandas.tseries.index.DatetimeIndex' & gt; [2014-10-14 19: 00: 05.861000-04: 00, ..., 2014-10-14 19: 06: 35.307000-04: 00] Length: 2042, Freak: None, Timezone: US / Eastern
There are duplicates in the index (and I need those entries):
& gt; My_series.index.get_duplicates () & lt; Class 'pandas.tseries.index.DatetimeIndex' & gt; [2014-10-14 23:00 00: 10.825000, ..., 2014-10-14 23: 05: 49.029000] Length: 65, Freak: None, Timezone: None < H3> Sampling from it:
Now, say that I use this series with
pandas.tseries.indexDatetimeIndex object
ts at specific time points Want to:
& gt; Import Arrow & gt; Start_time = arrow.get (2014, 10, 14, hours = 19, tzinfo = 'US / Eastern') & gt; End_time = start_time.replace (seconds = 400) & gt; Ts = pd.date_range (start = start_time.isoformat (), end = end_time.isoformat (), freq = '2200L')
Note that:
& gt; Start_time.isoformat () 2014-10-14T 9: 00: 00-04: 00 & gt; End_time.isoformat () 2014-10-14T19: 06: 40-04: 00
and
& gt; Ts & lt; Class 'pandas.tseries.index.DatetimeIndex' & gt; [2014-10-14 19: 00: 00-04: 00, ..., 2014-10-14 19: 06: 40.400000-04: 00] Length: 183, Freak: 2200 L, Timezone: tzoffset (Any No, - 14400)
When I sample it:
& gt; my_series [ts] .head () 1413327600000000000 NaN 1413327602200000000 NaN 1413327604400000000 NaN 1413327606600000000 NaN 1413327608800000000 NaN name: volume, dtype: float64
I have a series to get a
int64 Index, and no
day-time index index (to
ts ) which I expected:
& Gt; My_series.ix [ts] .index Int64Index ([1412636400000000000, 1412636402200000000, ...], dtype = 'int64')
The interesting thing is that the
int64 index I do "right" I do:
my_series.ix [ts] .index = pd.to_datetime (my_series.ix [ts] .index) .tz_localize ('UTC') Tz_convert ('America / Eastern.')
I can fix the problem.
Why does it return
int64 and not
DatetimeIndex ? How do I convert it into later words?
Here's the input that I see from pickle generated above), though not sure whether the arrow is; I am generating from isostrings
in
[42]: ts out [42]: & lt; Class 'pandas.tseries.index.DatetimeIndex' & gt; [2014-10-14 19: 00: 00-04: 00, ..., 2014-10-14 19:06 06:40 40.400000-04: 00] Length: 183, Freak: 2200 L, Timezone: Piatz. In Fix Offset (- 240) [43]: s.index out [43]: & lt; Class 'pandas.tseries.index.DatetimeIndex' & gt; [2014-10-14 1 9: 00: 05.861000-04: 00, ..., 2014-10-14 19: 06: 35.307000-04: 00] Length: 2042, Freak: No, timezone: US / Eastern
you do not have any overlapping values
[41]: s.index.tz_convert ( 'UTC') in. I.e. ts.tz_convert ('UTC')). Any () Out [41]: false
I can not reproduce the error where the index is not a DatetimeIndex note that it is 0kl5k0 (released today) and Many fixes have gone through Tz type of things.
You're actually doing a weird comparison that will not work in any way. They should be the same tz for selection / reindex, otherwise this does not make any sense.
Comments
Post a Comment