Stata ファイルのインポート
この演習では、pandas の pd.read_stata() 関数を使って Stata ファイルを DataFrame としてインポートする方法を習得しましょう。
前の演習で使用したファイル 'disarea.dta' は、引き続き作業ディレクトリに保存されています。
この演習はコースの一部です
Python でのデータインポート入門
演習の手順
pd.read_stata()を使って'disarea.dta'を DataFramedfに読み込んでください。- DataFrame
dfの先頭部分を出力してください。 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()