2017-04-04 3 views
1

나는 팬더가 같은 개체를 가지고 :팬더는 datetimeindex

hrIdx 
(array([ 23, 47, 71, 95, 119, 143, 167, 191, 215, 239, 263, 
     287, 311, 335, 359, 383, 407, 431, 455, 479, 503, 527, 
     551, 575, 599, ...,1592], dtype=int64),) 

나는 다음과 같은 노력하고 있어요 :

df_days[hrIdx] = df_days[hrIdx] + td(days=-1) 

df_days 
DatetimeIndex(['2015-05-24', '2015-05-24', '2015-05-24',..., '2016-03-19', 
       '2016-03-19', '2016-03-20'], 
       dtype='datetime64[ns]', length=7224, freq=None) 

type(df_days) 
<class 'pandas.tseries.index.DatetimeIndex'> 

나뿐만 인덱스의 배열을 가지고

그러나 할당 작업이 실패합니다. 하루를 빼는 오른쪽 작업은 정상적으로 작동합니다.

오류는 다음과 같습니다

raise TypeError("Index does not support mutable operations") 
TypeError: Index does not support mutable operations 

내가 위 달성하기 위해 노력했다처럼 df_days의 특정 요소를 변경하는 적절한 방법은 무엇입니까?

편집 :

from datetime import timedelta as td 

답변

2

팬더의 문서를 참조하는, 내가 발견이 : 다음

tdeltas = pd.TimedeltaIndex([str((0-int(i in hrIdx)))+' days' for i in xrange(len(df_days))]) 

과 :

당신이 그 코드와 함께이 트릭을 사용할 수 있습니다

http://pandas.pydata.org/pandas-docs/stable/timedeltas.html#id1

df_days = df_days + tdeltas 

참고 : 나는 판다 (0.19) 최신판의 문서를보고있다.