重命名类别
可领养狗数据集中的 likes_children 列需要更新。下面是当前的频数统计:
Maybe? 1718
yes 1172
no 47
两个明显问题是大小写不一致,以及 Maybe? 类别中包含 ?。数据应更干净一些,现请您做几处修改。
本练习是课程的一部分
在 Python 中处理分类数据
练习说明
- 创建一个名为
my_changes的字典,将Maybe?类别更新为Maybe。 - 使用
my_changes字典重命名likes_children中的类别。 - 再次更新类别,使所有类别都变为大写,使用
.upper()方法。 - 打印更新后
likes_childrenSeries 的类别。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create the my_changes dictionary
____
# Rename the categories listed in the my_changes dictionary
dogs["likes_children"] = ____
# Use a lambda function to convert all categories to uppercase using upper()
dogs["likes_children"] = dogs["likes_children"].____.____(lambda c: c.upper())
# Print the list of categories
print(____)