■ DataFrame 클래스의 tail 메소드를 사용해 후행 데이터를 구하는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import pandas as pd dataFrame1 = pd.read_csv("titanic.csv") dataFrame2 = dataFrame1.tail(8) print(dataFrame2) """ PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked 883 884 0 2 Banfield, Mr. Frederick James male 28.0 0 0 C.A./SOTON 34068 10.500 NaN S 884 885 0 3 Sutehall, Mr. Henry Jr male 25.0 0 0 SOTON/OQ 392076 7.050 NaN S 885 886 0 3 Rice, Mrs. William (Margaret Norton) female 39.0 0 5 382652 29.125 NaN Q 886 887 0 2 Montvila, Rev. Juozas male 27.0 0 0 211536 13.000 NaN S 887 888 1 1 Graham, Miss Margaret Edith female 19.0 0 0 112053 30.000 B42 S 888 889 0 3 Johnston, Miss Catherine Helen "Carrie" female NaN 1 2 W./C. 6607 23.450 NaN S 889 890 1 1 Behr, Mr. Karl Howell male 26.0 0 0 111369 30.000 C148 C 890 891 0 3 Dooley, Mr. Patrick male 32.0 0 0 370376 7.750 NaN Q """ |
▶ 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 명령을 실행했다.