使用已保存的映射
您正在使用某个数据集的子集,并被要求创建可视化来汇总结果。但按当前数据集的样子,您看到的全是数字!幸好,您之前创建并保存了字典(color_map、fuel_map 和 transmission_map),可以把这些列映射回原始的分类名称。数据集 used_cars_updated 已经预加载。下面展示了数据集的预览。请查看控制台以了解各列的数据类型。
engine_fuel color transmission price_usd
0 3 8 0 10900.00
1 3 1 0 5000.00
2 3 7 0 2800.00
本练习是课程的一部分
在 Python 中处理分类数据
练习说明
- 使用
color_map字典将"color"列还原为其原始取值。 - 使用
fuel_map字典将"engine_fuel"列还原为其原始取值。 - 使用
transmission_map字典将"transmission"列还原为其原始取值。 - 对数据集调用
.info(),查看dtypes是否发生了变化。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Update the color column using the color_map
used_cars_updated["color"] = ____
# Update the engine fuel column using the fuel_map
used_cars_updated["engine_fuel"] = ____
# Update the transmission column using the transmission_map
used_cars_updated["transmission"] = ____
# Print the info statement
print(____)