SAS 파일 가져오기
이번 연습에서는 SAS7BDAT과 pandas를 사용해 SAS 파일을 DataFrame으로 불러오는 방법을 익힐 거예요. 파일 'sales.sas7bdat'은 이미 작업 디렉터리에 있고, pandas와 matplotlib.pyplot도 아래와 같이 임포트되어 있어요:
import pandas as pd
import matplotlib.pyplot as plt
데이터는 Hill, Griffiths, Lim의 학부 교재 Principles of Econometrics 웹사이트의 자료를 바탕으로 했어요.
이 연습은 강의의 일부입니다
Python에서 데이터 가져오기 입문
연습 안내
- 라이브러리
sas7bdat에서 모듈SAS7BDAT을 임포트하세요. - 파일
'sales.sas7bdat'과 관련해, 객체file에 대해.to_data_frame()메서드를 사용하여 그 내용을 DataFramedf_sas로 로드하세요. - DataFrame
df_sas의 앞부분을 출력하세요. - 전체 스크립트를 실행해 히스토그램을 만들어 보세요!
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Import sas7bdat package
from ____ import ____
# Save file to a DataFrame: df_sas
with SAS7BDAT('sales.sas7bdat') as file:
____
# Print head of DataFrame
# Plot histogram of DataFrame features (pandas and pyplot already imported)
pd.DataFrame.hist(df_sas[['P']])
plt.ylabel('count')
plt.show()