開始使用免費開始

維持描述性

為了更深入了解舊金山機場旅客的體驗,品保部門向在各項分類中都給出最低分的旅客發出了一份質性問卷。這份問卷的目標是找出旅客對機場評價中常見的模式。

他們的回覆被存放在 survey_response 欄位。仔細查看後,你發現有些答案幾乎沒有內容,只填了最少的字元數。在這個練習中,你要篩選出字元數大於 40 的回覆,並使用 assert 陳述式確認你新的 DataFrame 只包含字元數為 40 或以上的回覆。

airlines DataFrame 已在你的環境中,且已將 pandaspd 匯入。

本練習屬於課程

用 Python 進行資料清理

檢視課程

練習說明

  • 使用 airlines DataFrame,透過 .str.len() 計算 survey_response 欄位每筆回覆的長度,並存入 resp_length
  • 篩選出 airlinesresp_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'])
編輯並執行程式碼