開始使用免費開始

臨界值

在本練習以及本章的其餘部分中,你會使用包含各家餐廳資料的 restaurants DataFrame。你的最終目標是建立一個餐廳推薦引擎,但在此之前,你需要先清理資料。

這個版本的 restaurants 來自多個來源,其中 cuisine_type 欄位有大量拼字錯誤,且理想上只應包含 italianamericanasian 這 3 種料理類型。由於出現太多獨特的分類,靠人工重新對應並不具擴充性,因此改用字串相似度會更好。

在開始之前,你想先用 thefuzzprocess.extract() 函式,找出每個類別最「遠」的錯字與正確拼法之間的相似度,藉此決定相似度分數的臨界點。

本練習屬於課程

用 Python 進行資料清理

檢視課程

動手互動練習

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

# Import process from thefuzz
____

# Store the unique values of cuisine_type in unique_types
unique_types = ____

# Calculate similarity of 'asian' to all values of unique_types
print(process.____('____', ____, limit = len(____)))

# Calculate similarity of 'american' to all values of unique_types
print(____('____', ____, ____))

# Calculate similarity of 'italian' to all values of unique_types
print(____)
編輯並執行程式碼