• 카테고리

    질문 & 답변
  • 세부 분야

    딥러닝 · 머신러닝

  • 해결 여부

    미해결

pd.merge() 질문

21.10.11 21:19 작성 조회수 120

0

pd.merge()에서  left_index=True, right_index=True 옵션 2개를 넣는 경우가 있는데

 

왜 넣는지 이해가 잘 안되서 질문 드립니다.

공식홈페이지 봤는데도 잘 이해가 안됩니다.

# OHE
train = train.merge(pd.get_dummies(train['R'], prefix='R'), left_index=True, right_index=True).drop(['R'], axis=1)

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html

https://www.kaggle.com/artgor/ventilator-pressure-prediction-eda-fe-and-models

답변 1

답변을 작성해보세요.

1

안녕하십니까, 

DataFrame에서 index는 RDBMS Table의 PK와 유사합니다. 

Pandas의 merge는 RDBMS의 Join과 유사합니다. RDBMS Table의 PK가 개별 Record를 고유하게 구분하는 key값이고, 보통 join은 이 pk를 기반으로 적용합니다. 

train.merge(pd.get_dummies(train['R'], prefix='R'), left_index=True, right_index=True).drop(['R'], axis=1)

일때 left_index는 train DataFrame의 index를 의미하며,  right_index는 pd.get_dummies(train['R'], prefix='R')로 반환되는 DataFrame의 index를 의미합니다. 따라서 이 train의 index(PK)와 pd.get_dummies(train['R'], prefix='R')로 반환되는 DataFrame의 index(PK)로 JOIN을 하라는 의미 입니다.