■ DataFrame 클래스의 sample 메소드에서 n 인자를 사용해 샘플 데이터를 구하는 방법을 보여준다.
▶ 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 |
import pandas as pd dataFrame1 = pd.read_csv("titanic.csv") dataFrame2 = dataFrame1.sample(n = 10) print(dataFrame2) """ PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked 360 361 0 3 Skoog, Mr. Wilhelm male 40.0 1 4 347088 27.9000 NaN S 109 110 1 3 Moran, Miss Bertha female NaN 1 0 371110 24.1500 NaN Q 752 753 0 3 Vande Velde, Mr. Johannes Joseph male 33.0 0 0 345780 9.5000 NaN S 537 538 1 1 LeRoy, Miss Bertha female 30.0 0 0 PC 17761 106.4250 NaN C 263 264 0 1 Harrison, Mr. William male 40.0 0 0 112059 0.0000 B94 S 858 859 1 3 Baclini, Mrs. Solomon (Latifa Qurban) female 24.0 0 3 2666 19.2583 NaN C 597 598 0 3 Johnson, Mr. Alfred male 49.0 0 0 LINE 0.0000 NaN S 454 455 0 3 Peduzzi, Mr. Joseph male NaN 0 0 A/5 2817 8.0500 NaN S 595 596 0 3 Van Impe, Mr. Jean Baptiste male 36.0 1 1 345773 24.1500 NaN S 264 265 0 3 Henry, Miss Delia female NaN 0 0 382649 7.7500 NaN Q """ |
▶ 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 명령을 실행했다.