修正 DataFrame 中的字串錯誤
你拿到 heroes 資料集,裡面包含多位漫畫英雄的資訊。不過,在進一步使用之前,你需要先做一些清理。
比較 Eye color、Hair color 和 Skin color 這三個欄位後,你會發現 Hair color 欄位中的字串是開頭大寫,而另外兩個欄位則是小寫。
此外,Gender 欄位的某些列有拼字錯誤(把 Female 寫成 Fmale)。
你的任務是:把 Hair color 欄位的字串都改成小寫,並修正 Gender 欄位中的拼字錯誤。
本練習屬於課程
Python 程式面試題實作練習
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Make all the values in the 'Hair color' column lowercased
heroes[____] = heroes[____].____.____
# Check the values in the 'Hair color' column
print(heroes['Hair color'].value_counts())