■ Series 클래스의 drop_duplicates 메소드를 사용해 중복 값을 제외한 데이터를 구하는 방법을 보여준다.
▶ 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 dataFrame = pd.read_csv("titanic.csv") series1 = dataFrame[["Sex", "SibSp"]] series2 = series1.drop_duplicates() print(series2) """ Sex SibSp 0 male 1 1 female 1 2 female 0 4 male 0 7 male 3 16 male 4 24 female 3 38 female 2 48 male 2 59 male 5 68 female 4 71 female 5 159 male 8 180 female 8 """ |
▶ 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 명령을 실행했다.