더북(TheBook)
import matplotlib.pyplot as plt
import datetime

class Hotplace:
    def __init__(self, dong_name, dong_code):
        self.name = dong_name
        self.code = dong_code

    # 그래프 그리기 메서드
    def graph_plot(self, popu_list, label_list, graph_title):
        plt.rc('font', family='Malgun Gothic')
        plt.title(graph_title)
        for i in range(len(popu_list)):
            plt.plot(range(24), popu_list[i], label=label_list[i])
        plt.legend()
        plt.xlabel('시간대')
        plt.ylabel('평균인구수')
        plt.xticks(range(24), range(24))
        plt.show()

    # 하위 목표 1 부분

    # 하위 목표 2
    def analysis2(self):
        weekday = [0 for i in range(24)]
        weekend = [0 for i in range(24)]
        for row in data:
            if row[2] == self.code:
                time, p = row[1], row[3]
                year, mon, day = int(row[0][:4]), int(row[0][4:6]), int(row[0][6:])
                num = datetime.date(year, mon, day).weekday()
                if num < 5:
                    weekday[time] += p
                else:
                    weekend[time] += p
        weekday_cnt, weekend_cnt = 0, 0
        for i in range(1, 32):
            if datetime.date(2019, 12, i).weekday() < 5:
                weekday_cnt += 1
            else:
                weekend_cnt += 1
        weekday = [w/weekday_cnt for w in weekday]
        weekend = [w/weekend_cnt for w in weekend]
        data_set = [weekday, weekend]
        labels = ['주중', '주말']
        title = self.name + ' 주중/주말 시간대별 평균인구'
        self.graph_plot(popu_list = data_set, label_list = labels, graph_title = title)

    # 하위 목표 3
    def analysis3(self):
        male = [0 for i in range(24)]
        female = [0 for i in range(24)]
        for row in data:
            if row[2] == self.code:
                time = row[1]
                male[time] += sum(row[4:18])
                female[time] += sum(row[18:32])
        male = [m/31 for m in male]
        female = [f/31 for f in female]
        data_set = [male, female]
        labels = ['남성', '여성']
        title = self.name + ' 남녀 시간대별 평균인구'
        self.graph_plot(popu_list = data_set, label_list = labels, graph_title = title)

# 하위 목표 4 부분
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.