■ DataFrame 클래스의 iloc 속성을 사용해 부분 데이터 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 |
import pandas as pd dataFrame1 = pd.read_excel("titanic.xlsx", sheet_name = "passengers") dataFrame2 = dataFrame1.iloc[9:25, 2:5] print(dataFrame2) """ Pclass Name Sex 9 2 Nasser, Mrs. Nicholas (Adele Achem) female 10 3 Sandstrom, Miss Marguerite Rut female 11 1 Bonnell, Miss Elizabeth female 12 3 Saundercock, Mr. William Henry male 13 3 Andersson, Mr. Anders Johan male 14 3 Vestrom, Miss Hulda Amanda Adolfina female 15 2 Hewlett, Mrs. (Mary D Kingcome) female 16 3 Rice, Master Eugene male 17 2 Williams, Mr. Charles Eugene male 18 3 Vander Planke, Mrs. Julius (Emelia Maria Vande... female 19 3 Masselmani, Mrs. Fatima female 20 2 Fynney, Mr. Joseph J male 21 2 Beesley, Mr. Lawrence male 22 3 McGowan, Miss Anna "Annie" female 23 1 Sloper, Mr. William Thompson male 24 3 Palsson, Miss Torborg Danira female """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
defusedxml==0.7.1 et_xmlfile==2.0.0 numpy==2.1.2 odfpy==1.4.1 openpyxl==3.1.5 pandas==2.2.3 python-calamine==0.2.3 python-dateutil==2.9.0.post0 pytz==2024.2 pyxlsb==1.0.10 six==1.16.0 tzdata==2024.2 xlrd==2.0.1 XlsxWriter==3.2.0 |
※ pip install "pandas[excel]" 명령을 실행했다.