데이터 과학 기반의 파이썬 빅데이터 분석 Chapter04 파이썬 프로그래밍 기초 연습문제

2023. 1. 5. 23:31Python/데이터 과학 기반의 파이썬 빅데이터 분석(한빛 아카데미)

07. pandas의 DataFrame 자료형으로 저장한 뒤 CSV파일에 저장하시오.

 

import pandas as pd
df = pd.DataFrame([[500, 450, 520, 610], [690, 700, 820, 900], [1100, 1030, 1200, 1380], [1500, 1650, 1700, 1850], [1990, 2020, 2300, 2420], [1020, 1600, 2200, 2550]], index = ['2015', '2016', '2017', '2018', '2019', '2020'], columns = ['1분기', '2분기', '3분기', '4분기'])
df

df.to_csv('Users', header = 'False')

08. 07번의 데이터를 이용하여 연도별 라인플롯 차트를 그리시오.

import matplotlib.pyplot as plt
x = ['first', 'second', 'third', 'fourth']
y = [[500, 690, 1100, 1500, 1990, 1020], [450, 700, 1030, 1650, 2020, 1600], [520, 820, 1200, 1700, 2300, 2200], [610, 900, 1380, 1850, 2420, 2550]]
plt.plot(x, y)
plt.title('2015-2020 Quarterly sales')
plt.xlabel('Quarters')
plt.ylabel('sales')
plt.legend(['2015', '2016', '2017', '2018', '2019', '2020'])
plt.show()