SQLAlchemy 결과를 그래프로 시각화하기
pandas와 Matplotlib를 활용해 데이터로 그림을 그릴 수도 있어요. 데이터 시각화는 탐색적 데이터 분석과 결과 전달 모두에 필수라는 점을 기억하세요!
이 연습은 강의의 일부입니다
Python으로 배우는 데이터베이스 입문
연습 안내
matplotlib.pyplot을plt로 임포트하세요.- 제공된
results에pd.DataFrame()을 적용해 DataFramedf를 만드세요. - DataFrame의 컬럼을 첫 번째 결과 객체의 컬럼인
results[0].keys()로 설정하여df.columns에 지정하세요. - DataFrame
df를 출력하세요. df에서plot.bar()메서드를 사용해 결과의 막대 그래프를 그리세요.plt.show()로 그래프를 표시하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Import pyplot as plt from matplotlib
# Create a DataFrame from the results: df
df = ____
# Set Column names
df.columns = ____
# Print the DataFrame
# Plot the DataFrame