■ DataFrame 클래스의 loc 속성을 사용해 특정 컬럼의 데이터를 구하는 방법을 보여준다.
▶ 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 |
import pandas as pd dataFrame1 = pd.read_csv("titanic.csv") dataFrame2 = dataFrame1.loc[:, "Name":"Age"] print(dataFrame2) """ Name Sex Age 0 Braund, Mr. Owen Harris male 22.0 1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 2 Heikkinen, Miss Laina female 26.0 3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 4 Allen, Mr. William Henry male 35.0 .. ... ... ... 886 Montvila, Rev. Juozas male 27.0 887 Graham, Miss Margaret Edith female 19.0 888 Johnston, Miss Catherine Helen "Carrie" female NaN 889 Behr, Mr. Karl Howell male 26.0 890 Dooley, Mr. Patrick male 32.0 [891 rows x 3 columns] """ |
▶ 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 명령을 실행했다.