列出全球最貧與最富的國家
「數值變數」的值是數字。你可以用「集中趨勢」來描述資料集裡最具代表性的典型值,以及用「離散程度」來表示分配的分散情形。
接下來幾個練習中,你會用這些統計量來探索 'per_capita_income.csv',其中包含各國人均(每人)所得的平均值。分析全球所得分配的第一步,是先查看並熟悉資料。
已經將 pandas 以 pd 導入。
本練習屬於課程
在 Python 中匯入與管理財務資料
練習說明
- 將
'per_capita_income.csv'載入為income。除了檔名外不需要其他引數。(注意這是 csv 檔。) - 使用
.info()檢視欄位名稱與資料型別。 - 使用
.sort_values(),依照包含所得資訊的欄位,將incomeDataFrame 以遞減順序排序。 - 使用
.head()顯示income的前 5 列,並用.tail()顯示最後 5 列。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the data
income = ____
# Inspect the result
income.info()
# Sort the data by income
income = income.sort_values('Income per Capita', ____)
# Display the first and last five rows
print(income.____())
print(income.____())