匯入 Stata 檔案
在這裡,你會學會如何使用 pandas 的 pd.read_stata() 函式,將 Stata 檔案匯入為 DataFrame。
上一題的檔案 'disarea.dta' 仍在你的工作目錄中。
本練習屬於課程
Python 資料匯入入門
練習說明
- 使用
pd.read_stata()將檔案 'disarea.dta' 載入為 DataFramedf。 - 列印 DataFrame
df的前幾列(head)。 - 透過繪製欄位
disa10的長條圖來視覺化結果。這段程式碼我們已為你準備好,直接執行即可!
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import pandas
import pandas as pd
# Load Stata file into a pandas DataFrame: df
# Print the head of the DataFrame df
# Plot histogram of one column of the DataFrame
pd.DataFrame.hist(df[['disa10']])
plt.xlabel('Extent of disease')
plt.ylabel('Number of countries')
plt.show()