從 Excel 檔案匯入工作表
在前面的練習中,你已經看到這個 Excel 檔案包含兩個工作表:'2002' 和 '2004'。
接下來要把它們匯入。
在本練習中,你會學到如何將已載入的 .xlsx 檔案中的任一 工作表匯入為一個 DataFrame。你可以 透過指定工作表的名稱或其索引來完成。
試算表 'battledeath.xlsx' 已經以 xls 載入。
本練習屬於課程
Python 資料匯入入門
練習說明
- 以名稱(字串)將工作表
'2004'載入為 DataFramedf1。 - 在終端機列印
df1的前幾列。 - 以索引(
0)將工作表2002載入為 DataFramedf2。 - 在終端機列印
df2的前幾列。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load a sheet into a DataFrame by name: df1
df1 = xls.parse(____)
# Print the head of the DataFrame df1
print(____)
# Load a sheet into a DataFrame by index: df2
# Print the head of the DataFrame df2
print(____)