■ concat 함수를 사용해 N개의 DataFrame 객체를 순서대로 결합하는 방법을 보여준다.
▶ 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 |
import pandas as pd import numpy as np dataFrame1 = pd.DataFrame(np.random.randn(10, 4)) print(dataFrame1) """ 0 1 2 3 0 0.792127 -1.345781 1.426220 -0.373232 1 -0.405740 1.017649 -1.425406 -0.210875 2 -1.441189 -1.933996 0.498967 0.125154 3 0.794920 0.183752 0.315564 -0.169499 4 0.137222 -0.541917 0.647770 0.446726 5 0.369762 -1.091014 0.281678 1.570859 6 0.381293 0.076755 0.528035 0.708578 7 -1.452200 -1.163749 -0.571872 0.239115 8 -2.380354 -1.172107 0.225631 0.613133 9 0.777913 1.788713 -0.383232 0.489444 """ print() dataFrameList = [dataFrame1[:3], dataFrame1[3:7], dataFrame1[7:]] dataFrame2 = pd.concat(dataFrameList) print(dataFrame2) """ 0 1 2 3 0 0.792127 -1.345781 1.426220 -0.373232 1 -0.405740 1.017649 -1.425406 -0.210875 2 -1.441189 -1.933996 0.498967 0.125154 3 0.794920 0.183752 0.315564 -0.169499 4 0.137222 -0.541917 0.647770 0.446726 5 0.369762 -1.091014 0.281678 1.570859 6 0.381293 0.076755 0.528035 0.708578 7 -1.452200 -1.163749 -0.571872 0.239115 8 -2.380354 -1.172107 0.225631 0.613133 9 0.777913 1.788713 -0.383232 0.489444 """ |
▶ 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 명령을 실행했다.