■ DataFrame 클래스의 sample 메소드에서 frac 인자를 사용해 샘플 데이터를 구하는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import pandas as pd dataFrame1 = pd.read_csv("titanic.csv") dataFrame2 = dataFrame1.sample(frac = 0.01) print(dataFrame2) """ PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked 113 114 0 3 Jussila, Miss Katriina female 20.0 1 0 4136 9.8250 NaN S 489 490 1 3 Coutts, Master Eden Leslie "Neville" male 9.0 1 1 C.A. 37671 15.9000 NaN S 425 426 0 3 Wiseman, Mr. Phillippe male NaN 0 0 A/4. 34244 7.2500 NaN S 454 455 0 3 Peduzzi, Mr. Joseph male NaN 0 0 A/5 2817 8.0500 NaN S 322 323 1 2 Slayter, Miss Hilda Mary female 30.0 0 0 234818 12.3500 NaN Q 838 839 1 3 Chip, Mr. Chang male 32.0 0 0 1601 56.4958 NaN S 159 160 0 3 Sage, Master Thomas Henry male NaN 8 2 CA. 2343 69.5500 NaN S 825 826 0 3 Flynn, Mr. John male NaN 0 0 368323 6.9500 NaN Q 114 115 0 3 Attalah, Miss Malake female 17.0 0 0 2627 14.4583 NaN C """ |
▶ 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 명령을 실행했다.