
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
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

