■ merge 함수에서 on/how 인자를 사용해 FULL JOIN 데이터를 만드는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import pandas as pd import numpy as np dataFrame1 = pd.DataFrame({"key" : ["A", "B", "C", "D"], "value" : np.random.randn(4)}) dataFrame2 = pd.DataFrame({"key" : ["B", "D", "D", "E"], "value" : np.random.randn(4)}) print(dataFrame1) """ key value 0 A -0.050330 1 B 0.754153 2 C 0.693311 3 D -0.543704 """ print() print(dataFrame2) """ key value 0 B -0.291885 1 D 0.871071 2 D 0.270238 3 E 0.509288 """ print() dataFrame3 = pd.merge(dataFrame1, dataFrame2, on = "key", how = "outer") # FULL JOIN print(dataFrame3) """ key value_x value_y 0 A -0.050330 NaN 1 B 0.754153 -0.291885 2 C 0.693311 NaN 3 D -0.543704 0.871071 4 D -0.543704 0.270238 5 E NaN 0.509288 """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 |
numpy==2.1.2 pandas==2.2.3 python-dateutil==2.9.0.post0 pytz==2024.2 six==1.16.0 tzdata==2024.2 |
※ pip install pandas 명령을 실행했다.