■ DataFrame 클래스의 iloc 속성을 사용해 행을 명시적으로 슬라이싱하는 방법을 보여준다.
▶ 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 |
import pandas as pd import numpy as np datetimeIndex = pd.date_range("20130101", periods = 6) dataFrame1 = pd.DataFrame(np.random.randn(6, 4), index = datetimeIndex, columns = list("ABCD")) print(dataFrame1) """ A B C D 2013-01-01 1.319131 1.050159 -0.329930 0.218507 2013-01-02 0.313371 -0.866423 0.648042 0.088910 2013-01-03 0.569949 -0.366839 -0.384350 0.130825 2013-01-04 -0.623062 -0.461133 1.438269 -0.315030 2013-01-05 -0.987991 0.187271 -0.835588 1.024690 2013-01-06 0.554150 1.119017 -0.064934 1.074642 """ print() dataFrame2 = dataFrame1.iloc[1:3, :] print(dataFrame2) """ A B C D 2013-01-02 0.313371 -0.866423 0.648042 0.088910 2013-01-03 0.569949 -0.366839 -0.384350 0.130825 """ |
▶ 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 명령을 실행했다.