DataFrame 的組成部分
為了更了解 DataFrame 物件,先認識它包含三個組成部分會很有幫助:
- values:一個二維的 NumPy 陣列,可透過
.to_numpy()方法存取。 - columns:欄位名稱的索引,可透過
.columns屬性存取。 - index:列(rows)的索引,可透過
.index屬性存取。
通常你可以把索引想成由字串或數字組成的清單,不過 pandas 的 Index 資料型別其實支援更進階的選項。(這些會在課程後面介紹。)
homelessness 已可使用。
本練習屬於課程
使用 pandas 進行資料操作
練習說明
- 使用別名
pd匯入pandas。 - 印出
homelessness中值的二維 NumPy 陣列。 - 印出
homelessness的欄位名稱。 - 印出
homelessness的索引。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import pandas using the alias pd
____
# Print the values of homelessness as a NumPy array
____
# Print the column index of homelessness
____
# Print the row index of homelessness
____