開始使用免費開始

重新命名類別

可領養狗狗資料集的 likes_children 欄位需要更新。以下是目前的次數統計:

Maybe?    1718
yes       1172
no          47

有兩點很明顯:大小寫不一致,以及 Maybe? 類別中出現了 ?。資料應該要更乾淨,你的任務是做一些調整。

本練習屬於課程

在 Python 中處理類別資料

檢視課程

練習說明

  • 建立名為 my_changes 的字典,將 Maybe? 類別更新為 Maybe
  • 使用 my_changes 字典重新命名 likes_children 的類別。
  • 再次更新類別,使「所有」類別都變成大寫,使用 .upper() 方法。
  • 列印更新後 likes_children Series 的各個類別。

動手互動練習

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

# 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(____)
編輯並執行程式碼