2017-04-11 4 views
3

데이터 프레임의 특정 인덱스 값을 변경하려고합니다. dataframe은 다음과 같습니다 : 0의 인덱스 인으로데이터 프레임의 특정 인덱스 값 바꾸기

start stop nested_in 
0 2015-11-10 05:42:00+00:00 2015-11-10 07:22:00+00:00 -1.0 
0 2015-11-10 05:42:00+00:00 2015-11-10 06:09:00+00:00 0.0 
0 2015-11-10 06:21:00+00:00 2015-11-10 06:37:00+00:00 0.0 
0 2015-11-10 06:42:00+00:00 2015-11-10 06:58:00+00:00 0.0 
0 2015-11-10 17:00:00+00:00 2015-11-10 21:55:00+00:00 -1.0 
0 2015-11-10 17:00:00+00:00 2015-11-10 17:45:00+00:00 4.0 
0 2015-11-10 17:45:00+00:00 2015-11-10 18:01:00+00:00 4.0 

.

나는 이런 식으로 뭔가하고 싶은 :

for i in range(0, df.size): 
    df.index[i] = i 

을하지만이 오류 다음 나에게주는

TypeError: Index does not support mutable operations 

내가 할 수 있어요 모든이있다 : 그래서위한

df.index = [i1, i2,... , i(df.size-1)] 

이 예 :

df.index = [0,1,2,3,4,5,6] 

내가 원하는 출력은 이것이다 :

start stop nested_in 
0 2015-11-10 05:42:00+00:00 2015-11-10 07:22:00+00:00 -1.0 
1 2015-11-10 05:42:00+00:00 2015-11-10 06:09:00+00:00 0.0 
2 2015-11-10 06:21:00+00:00 2015-11-10 06:37:00+00:00 0.0 
3 2015-11-10 06:42:00+00:00 2015-11-10 06:58:00+00:00 0.0 
4 2015-11-10 17:00:00+00:00 2015-11-10 21:55:00+00:00 -1.0 
5 2015-11-10 17:00:00+00:00 2015-11-10 17:45:00+00:00 4.0 
6 2015-11-10 17:45:00+00:00 2015-11-10 18:01:00+00:00 4.0 

나는 몇 가지 조사를했지만 직선 업 쉬운 해결책을 찾을 수 없습니다.

답변

2

당신은 갈 수 있습니다

df.reset_index(drop=True, inplace=True) 
0

이 시도 -

indices = range(df.shape[0]) # this can be anything as long as the length is same as that of the number of rows in the dataframe 
df['indices'] = indices 
df = df.set_index('indices') 

print df.head() 
관련 문제