始める無料で始める

Stata ファイルのインポート

この演習では、pandaspd.read_stata() 関数を使って Stata ファイルを DataFrame としてインポートする方法を習得しましょう。 前の演習で使用したファイル 'disarea.dta' は、引き続き作業ディレクトリに保存されています。

この演習はコースの一部です

Python でのデータインポート入門

コースを見る

演習の手順

  • pd.read_stata() を使って 'disarea.dta' を DataFrame df に読み込んでください。
  • 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()
コードを編集して実行