Ich habe einen Datenrahmen ab Montag Mitternacht und endet Samstag Mitternacht verschieben:derzeit keine Pandas Datenrahmen Index bedingt
>>> dfn.head()
Out[8]:
2012-02-27 00:00:00+00:00 3054679365.000
2012-02-27 01:00:00+00:00 1433475236.000
2012-02-27 02:00:00+00:00 1725293108.000
2012-02-27 03:00:00+00:00 1089842336.000
2012-02-27 04:00:00+00:00 1637301178.000
>>> dfn.tail()
2012-03-02 20:00:00+00:00 3696373423.000
2012-03-02 21:00:00+00:00 3423657296.000
2012-03-02 22:00:00+00:00 1887346076.000
2012-03-02 23:00:00+00:00 426382220.400
2012-03-03 00:00:00+00:00 759307738.400
dtype: float64
Die Frequenz ist stündlich, aber es gibt eine Pause auf ‚2012-03-02‘, die bei 1 beginnt statt Mitternacht am:
>>> dfn['2012-03-01'].tail()
Out[12]:
2012-03-01 19:00:00+00:00 2144039255.000
2012-03-01 20:00:00+00:00 4055718131.000
2012-03-01 21:00:00+00:00 1850226718.000
2012-03-01 22:00:00+00:00 738256967.900
2012-03-01 23:00:00+00:00 1163600574.000
Name: vol, dtype: float64
>>> dfn['2012-03-02'].head()
Out[11]:
2012-03-02 01:00:00+00:00 2364896887.000
2012-03-02 02:00:00+00:00 1598799781.000
2012-03-02 03:00:00+00:00 2011619242.000
2012-03-02 04:00:00+00:00 2408284057.000
2012-03-02 05:00:00+00:00 2084405746.000
Name: vol, dtype: float64
ich den Index bis um 1 Stunde ab dem Schnittpunkt von ‚2012-03-02‘ 01.00 verschieben will. Ich habe versucht, die folgenden:
trouble_spots = pd.date_range(start = dfn.index[trouble_loc], end = dfn.index[-1], freq='H', tz= 'Europe/London')
>>> trouble_spots
Out[13]: DatetimeIndex(['2012-03-02 01:00:00+00:00', '2012-03-02 02:00:00+00:00', '2012-03-02 03:00:00+00:00',.... '2012-03-02 22:00:00+00:00', '2012-03-02 23:00:00+00:00', '2012-03-03 00:00:00+00:00'], dtype='datetime64[ns]', freq='H', tz='Europe/London')
Das Problem ist, dass die folgende scheint nicht zu funktionieren:
dfn.index = dfn.index.map(lambda x: x - pd.Timedelta(1, 'h') if x in trouble_spots else x)
Es gibt den gleichen Index wie zuvor. Die Teile funktionieren separat:
>>> [x for x in dfn.index if x in trouble_spots]
Out[6]:
[Timestamp('2012-03-02 01:00:00+0000', tz='Europe/London'),
Timestamp('2012-03-02 02:00:00+0000', tz='Europe/London'),
......
Timestamp('2012-03-02 03:00:00+0000', tz='Europe/London'),
Timestamp('2012-03-02 21:00:00+0000', tz='Europe/London'),
Timestamp('2012-03-02 22:00:00+0000', tz='Europe/London'),
dfn.index.map(lambda x: x - pd.Timedelta(1, 'h'))
Out[5]:
DatetimeIndex(['2012-02-26 23:00:00+00:00', '2012-02-27 00:00:00+00:00', ... '2012-03-02 20:00:00+00:00', '2012-03-02 21:00:00+00:00', '2012-03-02 22:00:00+00:00', '2012-03-02 23:00:00+00:00'], dtype='datetime64[ns]', length=120, freq=None, tz='Europe/London')
Aber zusammen scheinen sie nicht zu arbeiten. Gibt es etwas, was mir hier fehlt?