Pandas 왼쪽 조인

1 개요[ | ]

Pandas 데이터프레임 레프트 조인

2 예시 1: 컬럼명 다른 경우[ | ]

Left-outer-join-operation.png

import pandas as pd
df1 = pd.DataFrame({'Date':['1/1/2020','1/2/2020','1/3/2020','1/4/2020'],'CountryID':[1,1,3,4],'Units': [40,25,30,35]})
df1
df2 = pd.DataFrame({'ID':[1,2,3],'County':['USA','Canada','Panama']})
df2
pd.merge(df1, df2, how='left', left_on='CountryID', right_on='ID').drop(columns='ID')

3 예시 2: 컬럼명 같은 경우[ | ]

import pandas as pd
df1 = pd.DataFrame({'Date':['1/1/2020','1/2/2020','1/3/2020','1/4/2020'],'CountryID':[1,1,3,4],'Units': [40,25,30,35]})
df1
df2 = pd.DataFrame({'CountryID':[1,2,3],'County':['USA','Canada','Panama']})
df2
pd.merge(df1, df2, how='left', on='CountryID')

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}