■ DataFrame 클래스의 loc 속성을 사용해 특정 조건을 만족하는 특정 컬럼 Series 객체를 구하는 방법을 보여준다.
▶ 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 |
import pandas as pd dataFrame = pd.read_excel("titanic.xlsx", sheet_name = "passengers") series = dataFrame.loc[dataFrame["Age"] > 35, "Name"] print(series) """ 1 Cumings, Mrs. John Bradley (Florence Briggs Th... 6 McCarthy, Mr. Timothy J 11 Bonnell, Miss Elizabeth 13 Andersson, Mr. Anders Johan 15 Hewlett, Mrs. (Mary D Kingcome) ... 865 Bystrom, Mrs. (Karolina) 871 Beckwith, Mrs. Richard Leonard (Sallie Monypeny) 873 Vander Cruyssen, Mr. Victor 879 Potter, Mrs. Thomas Jr (Lily Alexenia Wilson) 885 Rice, Mrs. William (Margaret Norton) Name: Name, Length: 217, dtype: object """ |
▶ 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]" 명령을 실행했다.