維持描述性
為了更深入了解舊金山機場旅客的體驗,品保部門向在各項分類中都給出最低分的旅客發出了一份質性問卷。這份問卷的目標是找出旅客對機場評價中常見的模式。
他們的回覆被存放在 survey_response 欄位。仔細查看後,你發現有些答案幾乎沒有內容,只填了最少的字元數。在這個練習中,你要篩選出字元數大於 40 的回覆,並使用 assert 陳述式確認你新的 DataFrame 只包含字元數為 40 或以上的回覆。
airlines DataFrame 已在你的環境中,且已將 pandas 以 pd 匯入。
本練習屬於課程
用 Python 進行資料清理
練習說明
- 使用
airlinesDataFrame,透過.str.len()計算survey_response欄位每筆回覆的長度,並存入resp_length。 - 篩選出
airlines中resp_length大於40的列。 - 以
assert確認airlines_survey中最短的survey_response長度現在大於40。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Store length of each row in survey_response column
resp_length = ____
# Find rows in airlines where resp_length > 40
airlines_survey = airlines[____ > ____]
# Assert minimum survey_response length is > 40
assert ____.str.len().____ > _____
# Print new survey_response column
print(airlines_survey['survey_response'])