一、案例定位

原書 Data Formatting 的完整實作使用 8 筆電影偏好資料,讓 Copilot 依序標準化 Name、將 Age 的文字數字轉為真正數值、統一 Date Watched;過程中又暴露出「空白 Age 被變成 0」與「空白日期被變成 1900-01-00」等新錯誤。

二、學習目標

三、案例情境

來源資料故意混合大小寫、額外空格、文字數字、不同日期格式、引號與空白值。原書用這個案例證明資料清理必須有順序,尤其缺漏值最好在格式轉換前處理。

四、開始資料

Name Age Favorite Genre Rating Date Watched
JOHN doe 25 Action 5 1/2/2024
alice SMITH 32 drama four "2024-02-01"
BOB 29 comedy 3 2/1/2024
jane doe 空白 Horror 空白 1/2/2024
MIKE 45 ACTION 2 1/2/2024
lucY 30 Sci-fi 4 2/1/2024
johnny 28 drama 4.5 空白
ANNA 40 Romance three 1/2/2024

五、Excel/R/AI 分析方法

原書依序提示:

  1. Standardize the text in the column Name: trim extra spaces and use proper capitalization.
  2. Convert all text-formatted numbers in the Age column to actual numeric values.
  3. Convert all dates in the column Date Watched to the format YYYY-MM-DD.
  4. 對帶引號日期再要求移除 quotation marks。

Copilot 第二輪日期公式之一為:=SUBSTITUTE(TEXT([@[Date Watched]],"yyyy-mm-dd"),"""",""),但空白日期因此變成 1900-01-00,需要再修改公式保留空白。

六、計算結果

原書最終畫面可確認: