두 개의 DataFrame을 합치는 함수.
merge(right, how=‘inner’, on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=False, suffixes=(‘_x’, ‘_y’), copy=True, indicator=False, validate=None)
# user_df DateFrame
UserID | Age | Name
-------------------
1 | 40 | Adam
2 | 28 | Alex
3 | 60 | Billy
===================
# money_df DateFrame
ID | Money
-------------------
1 | 15000
2 | 8000
3 | 2000
>> user_df.merge(money_df, left_on="UserID", right_on="ID")
UserID | Age | Name | ID | Money
------------------------------------
0 1 | 40 | Adam | 1 | 15000
1 1 | 40 | Adam | 2 | 8000
2 1 | 40 | Adam | 3 | 2000
3 2 | 28 | Alex | 1 | 15000
4 2 | 28 | Alex | 2 | 8000
5 2 | 28 | Alex | 3 | 2000
6 3 | 60 | Billy| 1 | 15000
7 3 | 60 | Billy| 2 | 8000
8 3 | 60 | Billy| 3 | 2000
# user_df DateFrame
ID | Age | Name
-------------------
1 | 40 | Adam
2 | 28 | Alex
3 | 60 | Billy
===================
# money_df DateFrame
ID | Money
-------------------
1 | 15000
2 | 8000
3 | 2000
>> user_df.merge(money_df) # = user_df.merge(money_df, on="ID")
UserID | Age | Name | ID | Money
------------------------------------
0 1 | 40 | Adam | 1 | 15000
1 1 | 40 | Adam | 2 | 8000
2 1 | 40 | Adam | 3 | 2000
3 2 | 28 | Alex | 1 | 15000
4 2 | 28 | Alex | 2 | 8000
5 2 | 28 | Alex | 3 | 2000
6 3 | 60 | Billy| 1 | 15000
7 3 | 60 | Billy| 2 | 8000
8 3 | 60 | Billy| 3 | 2000
>> result_df = pd.merge(user_df, money_df)
>> print(result_df)
UserID | Age | Name | ID | Money
------------------------------------
0 1 | 40 | Adam | 1 | 15000
1 1 | 40 | Adam | 2 | 8000
2 1 | 40 | Adam | 3 | 2000
3 2 | 28 | Alex | 1 | 15000
4 2 | 28 | Alex | 2 | 8000
5 2 | 28 | Alex | 3 | 2000
6 3 | 60 | Billy| 1 | 15000
7 3 | 60 | Billy| 2 | 8000
8 3 | 60 | Billy| 3 | 2000
Pandas Merge 함수는 추후 따로 정리예정