1. Learn
  2. /
  3. 课程
  4. /
  5. Python 数据清洗

Connected

道练习

阈值(cutoff point)

在本练习以及本章余下内容中,您将使用包含多家餐厅数据的 restaurants DataFrame。您的最终目标是构建一个餐厅推荐引擎,但首先需要清理数据。

这个版本的 restaurants 来自多个来源,其中 cuisine_type 列充满了拼写错误,按理只应包含 italian、american 和 asian 这 3 种菜系类型。类别太多,手动重映射不可扩展,因此更适合使用字符串相似度。

在此之前,您需要用 thefuzz 的 process.extract() 函数,为每个类别找到最"远"的拼写错误对应的相似度分数,从而确定相似度的阈值。

说明 1 / 共 2 个

undefined XP
    1
    2
  • 从 thefuzz 导入 process。
  • 将唯一的 cuisine_type 存入 unique_types。
  • 使用 process.extract() 计算 'asian'、'american' 和 'italian' 与所有可能 cuisine_type 的相似度,并返回所有可能的匹配结果。