MulaiMulai sekarang secara gratis

Importing Stata files

Here, you'll gain expertise in importing Stata files as DataFrames using the pd.read_stata() function from pandas. The last exercise's file, 'disarea.dta', is still in your working directory.

Latihan ini adalah bagian dari kursus

Introduction to Importing Data in Python

Lihat Kursus

Petunjuk latihan

  • Use pd.read_stata() to load the file 'disarea.dta' into the DataFrame df.
  • Print the head of the DataFrame df.
  • Visualize your results by plotting a histogram of the column disa10. We’ve already provided this code for you, so just run it!

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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()
Edit dan Jalankan Kode