開始使用免費開始

分層抽樣

你是某機構的一員,該機構向全國具代表性的 14 到 20 歲青少年樣本發送了一份問卷。上傳的資料集 youth_survey 紀錄了受訪者的 AgeHeight (in inches)Weight (in pounds)Gender,以及自行回報的多選題 How would you describe your weight?

在這個練習中,你要從資料集中建立一個分層且加權的樣本,抽取 1% 的受訪者。pandas 已匯入為 pd

資料集中包含所有受訪者的性別資訊,因此你會使用 Gender 欄作為分層欄位。

本練習屬於課程

使用 Python 分析問卷資料

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Calculate the percentage of female and male respondents
print(youth_survey.Gender____(normalize=____) * 100)
編輯並執行程式碼