커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
reset index 기능을 잘 이해하지 못했습니다.
undefined주차
북마크
박*순
댓글
1
추천
0
조회수
13
조회수
13
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.



df = fdr.DataReader('005930','2018')

df=df[['Close']]

df['이동평균선']=df.rolling(3).mean().shift(1

df['action']=np.where(df['Close']>df['이동평균선'],'buy','sell')

df.iloc[-1,-1]='sell' #action이 마지막

cond1=(df['action']=='buy')&(df['action'].shift(1)=='sell')

cond2=(df['action']=='sell')&(df['action'].shift(1)=='buy'

df_buy=df[cond1]

df_sell=df[cond2]

df_result=pd.concat([df_buy,df_sell],axis=1

df_result



일때 이런 결과가 나옵니다.

스파르타 즉문즉답



df_buy=df[cond1]는 이렇게


df_buy=df[cond2].reset_index() 는 아래와 같이 나옵니다.

제가 보기에는 index 가 붙은 것 빼고는 차이가 없어보이는데 어떻게 아래와같이 reset_index가 붙어서 저런 큰 차이가 났는지 궁금합니다.

제가 reset_index의 기능을 잘 이해하지 못한 것 같아요 ㅠㅠ



df = fdr.DataReader('005930','2018')

df=df[['Close']]

df['이동평균선']=df.rolling(3).mean().shift(1#비교하기 위해 한칸 내린다. 

df['action']=np.where(df['Close']>df['이동평균선'],'buy','sell')

df.iloc[-1,-1]='sell' #action이 마지막

cond1=(df['action']=='buy')&(df['action'].shift(1)=='sell'#이게 진짜 사는 시점

cond2=(df['action']=='sell')&(df['action'].shift(1)=='buy'

df_buy=df[cond1].reset_index()

df_sell=df[cond2].reset_index()

df_result=pd.concat([df_buy,df_sell],axis=1)

df_result

스파르타 즉문즉답








취소
 공유
취소
댓글 0
댓글 알림
나의얼굴