使用 pandas 載入資料
在訓練機器學習模型之前,你必須先匯入資料。方法有很多,但這裡我們先用 pandas 的單行指令:pd.read_csv()。回想影片說明,第一個引數用來指定路徑或 URL,其餘引數都是可選的。
在本練習中,你會匯入 King County 的房價資料集,之後在本章中我們會用它來訓練線性模型。
本練習屬於課程
Python 的 TensorFlow 入門
練習說明
- 以別名
pd匯入pandas。 - 將路徑指定給名為
data_path的字串變數。 - 將資料集載入為名為
housing的 pandas 資料框。 - 印出
housing的price欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import pandas under the alias pd
____
# Assign the path to a string variable named data_path
____ = 'kc_house_data.csv'
# Load the dataset as a dataframe named housing
____ = pd.read_csv(____)
# Print the price column of housing
print(____)